-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathproxy-scanner.py
executable file
·95 lines (75 loc) · 2.27 KB
/
proxy-scanner.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
#!/usr/bin/python3
import sys
import os
import socket
import urllib
from random import randint
# Often used proxy ports
proxy_ports = [3128, 8080, 8181, 8000, 1080, 80]
# URL we try to fetch
get_host = "www.google.com"
socket.setdefaulttimeout(3)
# get a list of ips from start / stop ip
def get_ips(start_ip, stop_ip):
ips = []
tmp = []
for i in start_ip.split('.'):
tmp.append("%02X" % int(i))
start_dec = int(''.join(tmp), 16)
tmp = []
for i in stop_ip.split('.'):
tmp.append("%02X" % int(i))
stop_dec = int(''.join(tmp), 16)
while(start_dec < stop_dec + 1):
bytes = []
bytes.append(str(int(start_dec / 16777216)))
rem = start_dec % 16777216
bytes.append(str(int(rem / 65536)))
rem = rem % 65536
bytes.append(str(int(rem / 256)))
rem = rem % 256
bytes.append(str(rem))
ips.append(".".join(bytes))
start_dec += 1
return ips
# try to connect to the proxy and fetch an url
def proxy_scan(ip):
# for every proxy port
for port in proxy_ports:
try:
# try to connect to the proxy on that port
s = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
s.connect((ip, port))
print(ip + ":" + str(port) + " OPEN")
# try to fetch the url
req = "GET " + get_host + " HTTP/1.0\r\n"
print(req)
s.send(req.encode())
s.send("\r\n".encode())
# get and print response
while 1:
data = s.recv(1024)
if not data:
break
print(data)
s.close()
except socket.error:
print(ip + ":" + str(port) + " Connection refused")
# parsing parameter
if len(sys.argv) < 2:
print(sys.argv[0] + ": <start_ip-stop_ip>")
sys.exit(1)
else:
if len(sys.argv) == 3:
get_host = sys.argv[2]
if sys.argv[1].find('-') > 0:
start_ip, stop_ip = sys.argv[1].split("-")
ips = get_ips(start_ip, stop_ip)
while len(ips) > 0:
i = randint(0, len(ips) - 1)
lookup_ip = str(ips[i])
del ips[i]
proxy_scan(lookup_ip)
else:
proxy_scan(sys.argv[1])