-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path04_ping_sweeper.py
More file actions
30 lines (24 loc) · 833 Bytes
/
Copy path04_ping_sweeper.py
File metadata and controls
30 lines (24 loc) · 833 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
import sys
from scapy.all import ICMP, IP, sr1
from netaddr import IPNetwork
def ping_sweep(network, netmask):
live_hosts = []
total_hosts = 0
scanned_hosts = 0
ip_network = IPNetwork(network + '/' + netmask)
for host in ip_network.iter_hosts():
total_hosts += 1
for host in ip_network.iter_hosts():
scanned_hosts += 1
print(f"Scanning: {scanned_hosts}/{total_hosts}", end="\r")
response = sr1(IP(dst=str(host))/ICMP(), timeout=1, verbose=0)
if response is not None:
live_hosts.append(str(host))
print(f"Host {host} is online.")
return live_hosts
if __name__ == "__main__":
network = sys.argv[1]
netmask = sys.argv[2]
live_hosts = ping_sweep(network, netmask)
print("Completed\n")
print(f"Live hosts: {live_hosts}")