Skip to content

Commit 74e0b94

Browse files
rootroot
root
authored and
root
committed
scapy-port-scanning-script
1 parent c9dc0b3 commit 74e0b94

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

scapy-demo-portscanning.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from scapy.all import *
2+
3+
# First we have to decleare the handshakes
4+
SYN = 0x02
5+
RST = 0x04
6+
ACK = 0x10
7+
8+
target = input("Enter the target IP or Domain: ")
9+
10+
for port in [
11+
21, # FTP
12+
22, # SSH
13+
23, # Telnet
14+
25, # SMTP
15+
80, # HTTP
16+
443, # HTTPS
17+
3306, # MySQL
18+
1433, # MSSQL
19+
5432, # PostgreSQL
20+
53, # DNS
21+
3389, # RDP
22+
137, # NetBIOS
23+
138, # NetBIOS
24+
139, # NetBIOS
25+
445, # SMB
26+
2049, # NFS
27+
161, # SNMP
28+
]:
29+
tcp_connect = sr1(IP(dst=target)/TCP(sport=RandShort(), dport=port, flags="S"), timeout=1, verbose=False)
30+
if tcp_connect and tcp_connect.haslayer(TCP):
31+
response_flags = tcp_connect.getlayer(TCP).flags
32+
if response_flags == (SYN + ACK):
33+
snd_rst = send(IP(dst=target)/TCP(sport=RandShort(), dport=port, flags="AR"), verbose=False)
34+
print("{} is open!".format(port))
35+
elif response_flags == (RST + ACK):
36+
print("{} is closed!".format(port))
37+
else:
38+
print("{} is closed!".format(port))

0 commit comments

Comments
 (0)