-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoMap.py
More file actions
75 lines (64 loc) · 2.5 KB
/
Copy pathNoMap.py
File metadata and controls
75 lines (64 loc) · 2.5 KB
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
import sys
import socket
import optparse
import threading
import queue
class PortScaner(threading.Thread):
def __init__(self, portqueue, ip, timeout=3)
threading.Thread.__init__(self)
self._portqueue = portqueue
self._ip = ip
self._timeout = timeout
def run(self):
while True:
if self._portqueue.empty():
break
port = self._portqueue.get(timeout=3)
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(self._timeout)
result_code = s.connect_ex((self._ip, port))
if result_code == 0:
sys.stdout.write("[%d] OPEN\n" % port)
except Exception as e:
print(e)
finally:
s.close()
def StartScan(targetip, port, threadNum):
portList = []
portNum = port
if '-' in port:
for i in range(int(port.split('-')[0]),int(port.split('-')[1])+1):
portList.append(i)
else:
portList.append(int(port))
ip = targetip
threrads = []
threadNumber = threadNum
portQueue = queue.Queue()
for port in portList:
portQueue.put(port)
for t in range(threadNumber):
threads.append(PortScaner(portQueue, ip, timeout=3))
for thread in threads:
thread.start()
for thread in threads:
thread.join()
def banner():
print(
# # # #
## # #### ## ## ## #####
# # # # # # # # # # # # #
# # # # # # # # # # # #
# # # # # # # ###### #####
# ## # # # # # # #
# # #### # # # # #
)
if __name__ == '__main__':
banner()
parser = optparse.OptionParser('Example : python %prog -i 127.0.0.1 -p 80 \n python %prog -i 127.0.0.1 -p 1-100\n')
parser.add_option('-i','--ip',dest='targetIP',default='127.0.0.1',type='string',help='target ip')
parser.add_option('-p','--port', dest='port', default='80', type='string', help='scan port')
parser.add_option('-t','--thread', dest='threadNum', default=100, type='int', help='scan thread number')
(options,args) = parser.parse_args()
StartScan(options.targetIP, options.port, options.threadNum)