-
Notifications
You must be signed in to change notification settings - Fork 114
/
portscan.py
39 lines (35 loc) · 1 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
import socket
import sys
Timeout = 3.0
def scan(ip,port):
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.settimeout(Timeout)
try:
server.connect((ip,port))
print '%s:%s'%(ip,port)
except Exception as err:
print('%s'%(ip))
finally:
server.close()
if __name__ == '__main__':
if len(sys.argv)!=4:
print '[!]Wrong parameter'
print 'Usage:'
print '%s <port> <BeginIP> <EndIP>'%(sys.argv[0])
sys.exit(0)
else:
Port = int(sys.argv[1])
BeginIP = sys.argv[2]
EndIP = sys.argv[3]
try:
socket.inet_aton(BeginIP)
socket.inet_aton(EndIP)
except:
print "[!]input error"
sys.exit(0)
IPRange = BeginIP[0:BeginIP.rfind('.')]
begin = BeginIP[BeginIP.rfind('.') + 1:]
end = EndIP[EndIP.rfind('.') + 1:]
for i in range(int(begin), int(end)+1):
strIP = "%s.%s" % (IPRange, i)
scan(strIP,Port)