-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvancedScan.py
44 lines (40 loc) · 1.28 KB
/
AdvancedScan.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
from socket import *
import optparse
from threading import *
def connScan(Host, Port):
try:
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((Host, Port))
print('[+] %d/tcp Open' %Port)
except:
print('[+] %d/tcp Closed' % Port)
finally:
sock.close()
def portScan(Host, Ports):
try:
tgtIP = gethostbyname(Host)
except:
print('Unknown Host %s ' %Host)
try:
tgtName = gethostbyaddr(tgtIP)
print('[+] Scan result for: ' + tgtName[0])
except:
print('[+] Scan result for: ' + tgtIP)
setdefaulttimeout(1)
for Port in Ports:
t = Thread(target=connScan, args=(Host, int(Port)))
t.start()
def main():
parser = optparse.OptionParser("Usage of program: " + "-H <target_host> -p <target_port>")
parser.add_option("-H", dest="tgtHost", type="string", help="specify target host")
parser.add_option("-p", dest="tgtPort", type="string", help="specify target ports separeted by comma")
(options, args) = parser.parse_args()
tgtHost = options.tgtHost
tgtPort = str(options.tgtPort).split(',')
if (tgtHost == None) | (tgtPort == None):
print(parser.usage)
exit(0)
else:
portScan(tgtHost, tgtPort)
if __name__ == '__main__':
main()