-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.py
52 lines (42 loc) · 1.67 KB
/
scanner.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
import argparse
import concurrent.futures
from rich.console import Console
from rich.live import Live
from table import create_table
from utils import perform_nmap_scan, scan_network
def parse_arguments():
parser = argparse.ArgumentParser(description="Network Scanner")
parser.add_argument(
"--network", default="192.168.0.1/24", help="Network range to scan"
)
parser.add_argument(
"--timeout", type=int, default=1, help="Timeout for ARP requests"
)
return parser.parse_args()
def main():
args = parse_arguments()
table = create_table()
console = Console(log_path="network_scan.log", log_time_format="[%X]")
with console.status("[bold green]Scanning Network...") as status:
answered_list = scan_network(args.network, args.timeout)
with Live(table, refresh_per_second=4):
with concurrent.futures.ThreadPoolExecutor() as executor:
future_to_ip = {
executor.submit(perform_nmap_scan, response): response.psrc
for _, response in answered_list
}
for future in concurrent.futures.as_completed(future_to_ip):
ip = future_to_ip[future]
try:
mac, hostname, vendor, status = future.result()
table.add_row(
":green_circle:" if status == "up" else ":red_circle:",
ip,
mac,
hostname or "N/A",
vendor or "Unknown",
)
except Exception as e:
console.log(f"Failed to scan {ip}: {e}")
if __name__ == "__main__":
main()