-
Notifications
You must be signed in to change notification settings - Fork 0
/
nmap_auto.py
56 lines (40 loc) · 1.76 KB
/
nmap_auto.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
48
49
50
51
52
53
54
55
56
from scapy.all import *
import sys
import os
if len(sys.argv) < 3:
print("Usage: nmap_auto.py address porta-portb-portc")
sys.exit()
ports = os.sys.argv[2].split("-")
ports = [int(port) for port in ports]
print("EXECUTING UDP SCAN ON "+os.sys.argv[1]+" ports "+str(ports))
ans, unans = sr(IP(dst=os.sys.argv[1]) / UDP(dport=ports), timeout=2, verbose=False)
ans.summary(lambda(s, r): r.sprintf("%IP.sport%: open"))
unans.summary(lambda(s): s.sprintf("%IP.dport%: open|filtered"))
print("EXECUTING SYN SCAN ON "+os.sys.argv[1]+" ports "+str(ports))
ans, unans = sr(IP(dst=os.sys.argv[1])/TCP(dport=ports, flags="S"), timeout=2, verbose=False)
for s, r in ans:
if s[TCP].dport == r[TCP].sport:
print(str(s[TCP].dport) + ": open")
for s in unans:
print(str(s[TCP].dport) + ": closed")
print("EXECUTING ACK SCAN ON "+os.sys.argv[1]+" ports "+str(ports))
ans, unans = sr(IP(dst=os.sys.argv[1])/TCP(dport=ports, flags="A"), timeout=1, verbose=False)
for s, r in ans:
if s[TCP].dport == r[TCP].sport:
print(str(s[TCP].dport) + ": open")
for s in unans:
print(str(s[TCP].dport) + ": open|filtered")
print("EXECUTING NULL SCAN ON "+os.sys.argv[1]+" ports "+str(ports))
ans, unans = sr(IP(dst=os.sys.argv[1])/TCP(dport=ports, flags=""), timeout=1, verbose=False)
for s, r in ans:
if s[TCP].dport == r[TCP].sport:
print(str(s[TCP].dport) + ": open")
for s in unans:
print(str(s[TCP].dport) + ": open|filtered")
print("EXECUTING XMAS SCAN ON "+os.sys.argv[1]+" ports "+str(ports))
ans, unans = sr(IP(dst=os.sys.argv[1])/TCP(dport=ports, flags="FPU"), timeout=1, verbose=False)
for s, r in ans:
if s[TCP].dport == r[TCP].sport:
print(str(s[TCP].dport) + ": open")
for s in unans:
print(str(s[TCP].dport) + ": open|filtered")