Skip to content

Commit

Permalink
Merge pull request #17 from asvvvad/master
Browse files Browse the repository at this point in the history
Added get and refresh IP options
  • Loading branch information
ruped24 authored Jul 22, 2020
2 parents 47cc6ad + fd06f54 commit 94fda91
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions toriptables2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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
Expand Down Expand Up @@ -39,7 +40,7 @@ def __init__(self):
TransPort %s
DNSPort %s
''' % (basename(__file__), self.trans_port, self.virtual_net,
self.trans_port, self.local_dnsport)
self.trans_port, self.local_dnsport)

def flush_iptables_rules(self):
call(["iptables", "-F"])
Expand All @@ -58,27 +59,7 @@ def restart_tor():
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))

Expand Down Expand Up @@ -113,7 +94,28 @@ def restart_tor():
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=
Expand All @@ -126,6 +128,14 @@ def restart_tor():
'--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:
Expand All @@ -141,6 +151,11 @@ def restart_tor():
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:
Expand Down

0 comments on commit 94fda91

Please sign in to comment.