-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscapy-scan-icmp.py
More file actions
32 lines (25 loc) · 876 Bytes
/
scapy-scan-icmp.py
File metadata and controls
32 lines (25 loc) · 876 Bytes
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
#!/usr/bin/env python3
import scapy.all as scapy
import sys
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
# --------------------------------------------------
# FUNCTIONS
# --------------------------------------------------
def scan(target):
packet = scapy.IP(dst=target)/scapy.ICMP()
answer, noanswer = scapy.sr(packet, timeout=1, verbose=False)
for item in answer:
# item = (sent packet, received packet)
if item[1].type == 0:
print( f'ICMP echo-reply from {item[1].src}' )
# --------------------------------------------------
# MAIN
# --------------------------------------------------
if __name__ == '__main__':
if len(sys.argv)==2:
target = sys.argv[1]
print(f'scan {target} with ICMP')
scan(target)
else:
print(f'Usage: {sys.argv[0]} <target|range>')