-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulti_parser.py
47 lines (38 loc) · 1.05 KB
/
multi_parser.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from socket import *
import threading
import argparse
lock = threading.Lock()
openNum = 0
threads = []
def portScanner(host, port):
global openNum
try:
s = socket(AF_INET, SOCK_STREAM)
s.connect((host, port))
lock.acquire()
openNum += 1
print('[+] %d open' % port)
lock.release()
s.close()
except:
pass
def main():
p = argparse.ArgumentParser(description='Port scanner!.')
p.add_argument('-H', dest='hosts', type=str)
args = p.parse_args()
hostList = args.hosts.split(',')
setdefaulttimeout(1)
for host in hostList:
print('Scanning the host:%s......' % (host))
for p in range(1, 1024):
t = threading.Thread(target=portScanner, args=(host, p))
threads.append(t)
t.start()
for t in threads:
t.join()
print('[*] The host:%s scan is complete!' % (host))
print('[*] A total of %d open port ' % (openNum))
if __name__ == '__main__':
main()