Merge pull request #17 from asvvvad/master

Added get and refresh IP options
This commit is contained in:
Rupert Edwards 2020-07-22 15:13:55 -04:00 committed by GitHub
commit 94fda91db3
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 subprocess import call, check_call, CalledProcessError
from os.path import isfile, basename from os.path import isfile, basename
from os import devnull from os import devnull
import os
from sys import stdout, stderr from sys import stdout, stderr
from atexit import register from atexit import register
from argparse import ArgumentParser from argparse import ArgumentParser
@ -58,27 +59,7 @@ DNSPort %s
stdout=fnull, stderr=fnull) stdout=fnull, stderr=fnull)
if tor_restart is 0: if tor_restart is 0:
print(" {0}".format( self.get_ip()
"[\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))
except CalledProcessError as err: except CalledProcessError as err:
print("\033[91m[!] Command failed: %s\033[0m" % ' '.join(err.cmd)) print("\033[91m[!] Command failed: %s\033[0m" % ' '.join(err.cmd))
@ -113,7 +94,28 @@ DNSPort %s
self.tor_uid, "-j", "ACCEPT"]) self.tor_uid, "-j", "ACCEPT"])
call(["iptables", "-A", "OUTPUT", "-j", "REJECT"]) 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__': if __name__ == '__main__':
parser = ArgumentParser( parser = ArgumentParser(
description= description=
@ -126,6 +128,14 @@ if __name__ == '__main__':
'--flush', '--flush',
action='store_true', action='store_true',
help='This option flushes the iptables rules to default') 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() args = parser.parse_args()
try: try:
@ -141,6 +151,11 @@ if __name__ == '__main__':
load_tables.flush_iptables_rules() load_tables.flush_iptables_rules()
print(" {0}".format( print(" {0}".format(
"[\033[93m!\033[0m] Anonymizer status \033[91m[OFF]\033[0m")) "[\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: else:
parser.print_help() parser.print_help()
except Exception as err: except Exception as err: