-
Notifications
You must be signed in to change notification settings - Fork 49
/
tor_ip_switcher.py
executable file
·143 lines (122 loc) · 4.08 KB
/
tor_ip_switcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#! /usr/bin/env python2
"""
tor_switcher.py reloaded and refactored by Rupe to work with toriptables2.py.
tor_ip_switcher.py is a light GUI interface for issuing NEWNYM signals over TOR's control port.
Useful for making any DoS attack look like a DDoS attack.
"""
from commands import getoutput
from json import load
from random import random
from ScrolledText import ScrolledText
from telnetlib import Telnet
from thread import start_new_thread
from time import localtime, sleep
from Tkinter import *
from tkMessageBox import showerror
from urllib2 import URLError, urlopen
class Switcher(Tk):
def __init__(self):
Tk.__init__(self)
self.resizable(0, 0)
self.title(string=".o0O| TOR IP Switcher |O0o.")
self.host = StringVar()
self.port = IntVar()
self.passwd = StringVar()
self.time = DoubleVar()
self.host.set('localhost')
self.port.set('9051')
self.passwd.set('')
self.time.set('30')
Label(self, text='Host:').grid(row=1, column=1, sticky=E)
Label(self, text='Port:').grid(row=2, column=1, sticky=E)
Label(self, text='Password:').grid(row=3, column=1, sticky=E)
Label(self, text='Interval:').grid(row=4, column=1, sticky=E)
Entry(self, textvariable=self.host).grid(row=1, column=2, columnspan=2)
Entry(self, textvariable=self.port).grid(row=2, column=2, columnspan=2)
Entry(self, textvariable=self.passwd, show='*').grid(
row=3, column=2, columnspan=2)
Entry(self, textvariable=self.time).grid(row=4, column=2, columnspan=2)
Button(self, text='Start', command=self.start).grid(row=5, column=2)
Button(self, text='Stop', command=self.stop).grid(row=5, column=3)
self.output = ScrolledText(
self,
foreground="white",
background="black",
highlightcolor="white",
highlightbackground="purple",
wrap=WORD,
height=8,
width=40)
self.output.grid(row=1, column=4, rowspan=5, padx=4, pady=4)
def start(self):
self.write('TOR Switcher starting.')
self.ident = random()
start_new_thread(self.newnym, ())
def stop(self):
try:
self.write('TOR Switcher stopping.')
except:
pass
self.ident = random()
def write(self, message):
t = localtime()
try:
self.output.insert(END,
'[%02i:%02i:%02i] %s\n' % (t[3], t[4], t[5], message))
self.output.yview(MOVETO, 1.0)
except:
print('[%02i:%02i:%02i] %s\n' % (t[3], t[4], t[5], message))
def error(self):
showerror('TOR IP Switcher', 'Tor daemon not running!')
def newnym(self):
key = self.ident
host = self.host.get()
port = self.port.get()
passwd = self.passwd.get()
interval = self.time.get()
try:
telnet = Telnet(host, port)
if passwd == '':
telnet.write("AUTHENTICATE\r\n")
else:
telnet.write("AUTHENTICATE \"%s\"\r\n" % (passwd))
res = telnet.read_until('250 OK', 5)
if res.find('250 OK') > -1:
self.write('AUTHENTICATE accepted.')
else:
self.write('Control responded,' + "\n"
'Incorrect password: "%s"' % (passwd))
key = self.ident + 1
self.write('Quitting.')
except Exception:
self.write('There was an error!')
self.error()
key = self.ident + 1
self.write('Quitting.')
while key == self.ident:
try:
telnet.write("signal NEWNYM\r\n")
res = telnet.read_until('250 OK', 5)
if res.find('250 OK') > -1:
try:
my_new_ident = load(urlopen('https://check.torproject.org/api/ip'))['IP']
except (URLError, ValueError):
my_new_ident = getoutput('wget -qO - ident.me')
self.write('Your IP is %s' % (my_new_ident))
else:
key = self.ident + 1
self.write('Quitting.')
sleep(interval)
except Exception, ex:
self.write('There was an error: %s.' % (ex))
key = self.ident + 1
self.write('Quitting.')
try:
telnet.write("QUIT\r\n")
telnet.close()
except:
pass
if __name__ == '__main__':
mw = Switcher()
mw.mainloop()
mw.stop()