-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrichpingsweeper.py
More file actions
50 lines (44 loc) · 1.32 KB
/
richpingsweeper.py
File metadata and controls
50 lines (44 loc) · 1.32 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
48
49
50
"""
Python Pingsweeper script using Rich
"""
import os
import time
import itertools
import ipaddress
from subprocess import Popen, DEVNULL
from rich import print
from rich.console import Console
from rich.table import Table
CLEAR = "clear"
os.system(CLEAR)
localtime = time.asctime(time.localtime(time.time()))
active_list = []
inactive_list = []
p = {}
print("[green]Welcome to Ping Reporter![/green]")
print("[cyan]Please enter the network you wish to test...[/cyan]")
print("Example: < 192.168.10.0/24 >")
subnet = input("\nEnter network: ")
print("\n")
network = ipaddress.ip_network(subnet)
for n in network.hosts():
IP = str(n)
p[IP] = Popen(['ping', '-c', '4', '-i', '0.2', IP], stdout=DEVNULL)
while p:
for IP, proc in p.items():
if proc.poll() is not None:
del p[IP]
if proc.returncode == 0:
active_list.append(IP)
elif proc.returncode == 1:
inactive_list.append(IP)
else:
print(f"{IP} ERROR")
break
table = Table(title="PING REPORT \n" + localtime)
table.add_column("Active Hosts", justify="center", style="green")
table.add_column("Inactive Hosts", justify="center", style="red")
for (a, i) in itertools.zip_longest(active_list, inactive_list):
table.add_row(a, i)
console = Console()
console.print(table)