forked from Tu-tu-tu/SRCHunter
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathportscan.py
67 lines (59 loc) · 1.8 KB
/
portscan.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
import threading, socket, sys, cmd, os, Queue
lock = threading.Lock()
def GetQueue(host):
PortQueue = Queue.Queue()
ports = [11211,27017]
for port_list in range(1,10000):
ports.append(port_list)
for port in ports:
PortQueue.put((host,port))
return PortQueue
class ScanThread(threading.Thread):
def __init__(self,SingleQueue,outip):
threading.Thread.__init__(self)
self.setDaemon(True)
self.SingleQueue = SingleQueue
self.outip = outip
def Ping(self,scanIP, Port):
global OpenPort, lock
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
address = (scanIP, Port)
try:
sock.connect(address)
except:
sock.close()
return False
sock.close()
if lock.acquire():
print "[+] Get IP:%s Port:%s open" % (scanIP, str(Port))
self.outip.put(Port)
lock.release()
return True
def run(self):
while not self.SingleQueue.empty():
host,port = self.SingleQueue.get()
self.Ping(host,port)
class Work(object):
def __init__(self,scan_target = ""):
self.target = scan_target
self.result = []
def run(self):
ThreadList = []
SingleQueue = GetQueue(self.target)
resultQueue = Queue.Queue()
for i in range(0, 500):
t = ScanThread(SingleQueue,resultQueue)
ThreadList.append(t)
for t in ThreadList:
t.start()
for t in ThreadList:
t.join(0.1)
data = []
while not resultQueue.empty():
line = resultQueue.get()
data.append(line)
return data
#t = Work(scan_target = "176.28.50.165")#43.242.128.230
#print t.run()