-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipscan.py
More file actions
47 lines (38 loc) · 1.38 KB
/
ipscan.py
File metadata and controls
47 lines (38 loc) · 1.38 KB
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
import subprocess
import platform
from concurrent.futures import ThreadPoolExecutor
def is_live(ip):
"""Check if an IP is live using ping."""
param = "-n" if platform.system().lower() == "windows" else "-c"
try:
print(f"[*] Checking {ip}",end="\r")
subprocess.run(["ping", param, "1", ip], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
return ip
except subprocess.CalledProcessError:
return None
def scan_ip_range(start_ip, end_ip):
"""Scan a range of IPs and return the live ones."""
start_parts = list(map(int, start_ip.split('.')))
end_parts = list(map(int, end_ip.split('.')))
live_ips = []
with ThreadPoolExecutor() as executor:
futures = []
for i in range(start_parts[3], end_parts[3] + 1):
ip = f"{start_parts[0]}.{start_parts[1]}.{start_parts[2]}.{i}"
futures.append(executor.submit(is_live, ip))
for future in futures:
result = future.result()
if result:
live_ips.append(result)
return live_ips
if __name__ == "__main__":
start_ip = "192.168.1.1"
end_ip = "192.168.1.254"
print("Scanning for live IPs...\n")
live_ips = scan_ip_range(start_ip, end_ip)
if live_ips:
print("\nLive IPs found:")
for ip in live_ips:
print(ip)
else:
print("No live IPs found.")