Added get and refresh IP options

-i | --ip will get the public IP and -r | --refresh will change the IP and return the new one
This commit is contained in:
asvvvad 2020-07-22 17:43:58 +01:00 committed by GitHub
parent 47cc6ad347
commit fd06f54c8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ from commands import getoutput
from subprocess import call, check_call, CalledProcessError
from os.path import isfile, basename
from os import devnull
import os
from sys import stdout, stderr
from atexit import register
from argparse import ArgumentParser
@ -58,27 +59,7 @@ DNSPort %s
stdout=fnull, stderr=fnull)
if tor_restart is 0:
print(" {0}".format(
"[\033[92m+\033[0m] Anonymizer status \033[92m[ON]\033[0m"))
print(" {0}".format(
"[\033[92m*\033[0m] Getting public IP, please wait..."))
retries = 0
my_public_ip = None
while retries < 12 and not my_public_ip:
retries += 1
try:
my_public_ip = load(urlopen('https://check.torproject.org/api/ip'))['IP']
except URLError:
sleep(5)
print(" [\033[93m?\033[0m] Still waiting for IP address...")
except ValueError:
break
print
if not my_public_ip:
my_public_ip = getoutput('wget -qO - ifconfig.me')
if not my_public_ip:
exit(" \033[91m[!]\033[0m Can't get public ip address!")
print(" {0}".format("[\033[92m+\033[0m] Your IP is \033[92m%s\033[0m" % my_public_ip))
self.get_ip()
except CalledProcessError as err:
print("\033[91m[!] Command failed: %s\033[0m" % ' '.join(err.cmd))
@ -113,7 +94,28 @@ DNSPort %s
self.tor_uid, "-j", "ACCEPT"])
call(["iptables", "-A", "OUTPUT", "-j", "REJECT"])
def get_ip(self):
print(" {0}".format(
"[\033[92m+\033[0m] Anonymizer status \033[92m[ON]\033[0m"))
print(" {0}".format(
"[\033[92m*\033[0m] Getting public IP, please wait..."))
retries = 0
my_public_ip = None
while retries < 12 and not my_public_ip:
retries += 1
try:
my_public_ip = load(urlopen('https://check.torproject.org/api/ip'))['IP']
except URLError:
sleep(5)
print(" [\033[93m?\033[0m] Still waiting for IP address...")
except ValueError:
break
print
if not my_public_ip:
my_public_ip = getoutput('wget -qO - ifconfig.me')
if not my_public_ip:
exit(" \033[91m[!]\033[0m Can't get public ip address!")
print(" {0}".format("[\033[92m+\033[0m] Your IP is \033[92m%s\033[0m" % my_public_ip))
if __name__ == '__main__':
parser = ArgumentParser(
description=
@ -126,6 +128,14 @@ if __name__ == '__main__':
'--flush',
action='store_true',
help='This option flushes the iptables rules to default')
parser.add_argument('-r',
'--refresh',
action='store_true',
help='This option will change the circuit and gives another IP address')
parser.add_argument('-i',
'--ip',
action='store_true',
help='This option will output the current public IP address')
args = parser.parse_args()
try:
@ -141,6 +151,11 @@ if __name__ == '__main__':
load_tables.flush_iptables_rules()
print(" {0}".format(
"[\033[93m!\033[0m] Anonymizer status \033[91m[OFF]\033[0m"))
elif args.ip:
load_tables.get_ip()
elif args.refresh:
os.system("kill -HUP $(pidof tor)")
load_tables.get_ip()
else:
parser.print_help()
except Exception as err: