-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportscan
60 lines (47 loc) · 1.15 KB
/
portscan
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/3/5 下午4:33
# @Author : r00t
# @Site :
# @File : portScan.py
# @Software: PyCharm
import socket
import sys
from datetime import datetime
from multiprocessing.dummy import Pool as ThreadPool
socket.setdefaulttimeout(0.5)
port = sys.argv[0]
hostFileName = sys.argv[1]
t1 = datetime.now()
hosts=[]
def readHost(hostFileName):
fs = open(hostFileName,'r').readlines()
for host in fs:
hosts.append(int(host))
def useAge():
print
print "Useage:"
print
print "portScan.py Port hostFileName"
print
#print '_' * 60
#print 'Please wait, scanning...'
#print '_' * 60
def scan_port(port,host):
try:
s = socket.socket(2,1)
res = s.connect_ex((host,port))
if res == 0:
print 'Port {}: OPEN'.format(port)
s.close()
except Exception,e:
print str(e.message)
if __name__ == '__main__':
if len(sys.argv) == 2:
useAge()
pool = ThreadPool(processes=10)
results = pool.map(scan_port,hosts)
pool.close()
pool.join()
t2 = datetime.now() -t1
print t2