Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f937bbe25b |
@@ -4,26 +4,25 @@
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import socket
|
import socket
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from colorama import init, Fore
|
from colorama import init, Fore
|
||||||
from icmplib import async_multiping, ping, multiping
|
from icmplib import async_multiping, ping, multiping
|
||||||
|
|
||||||
|
|
||||||
init()
|
init()
|
||||||
GREEN = Fore.GREEN
|
GREEN = Fore.GREEN
|
||||||
RESET = Fore.RESET
|
RESET = Fore.RESET
|
||||||
GRAY = Fore.LIGHTBLACK_EX
|
GRAY = Fore.LIGHTBLACK_EX
|
||||||
|
|
||||||
|
|
||||||
def are_alive(addresses: List[str]) -> List[str]:
|
def are_alive(addresses: List[str]) -> List[str]:
|
||||||
return [host.address for host in multiping(addresses) if host.is_alive]
|
hosts = multiping(addresses)
|
||||||
|
return [host.address for host in hosts if host.is_alive]
|
||||||
|
|
||||||
|
|
||||||
def is_host_alive(host: str) -> bool:
|
def is_host_alive(host: str) -> bool:
|
||||||
if not ping(host, timeout=1, count=1).is_alive:
|
if ping(host, timeout=1, count=1).is_alive:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
print(f"{GRAY}{host:15} is not alive {RESET}")
|
print(f"{GRAY}{host:15} is not alive {RESET}")
|
||||||
return False
|
return False
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def is_port_open(host: str, port: int) -> bool:
|
def is_port_open(host: str, port: int) -> bool:
|
||||||
@@ -41,11 +40,14 @@ def is_port_open(host: str, port: int) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def is_subnet(ip: str) -> bool:
|
def is_subnet(ip: str) -> bool:
|
||||||
return "/" in ip
|
if "/" in ip:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def hosts_in_subnet(network: str) -> List[str]:
|
def hosts_in_subnet(network: str) -> List[str]:
|
||||||
if not is_subnet(network):
|
if not is_subnet:
|
||||||
print(f"{network} is not a network")
|
print(f"{network} is not a network")
|
||||||
|
|
||||||
return [str(_) for _ in ipaddress.ip_network(network).hosts()]
|
return [str(_) for _ in ipaddress.ip_network(network).hosts()]
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ def test_is_port_open():
|
|||||||
|
|
||||||
|
|
||||||
def test_is_subnet():
|
def test_is_subnet():
|
||||||
assert pscanner.is_subnet("192.168.1.0") == False
|
assert pscanner.is_subnet("192.168.1.0") is False
|
||||||
assert pscanner.is_subnet("192.168.0/24") == True
|
assert pscanner.is_subnet("192.168.0/24") is True
|
||||||
|
|
||||||
|
|
||||||
def test_hosts_in_subnet():
|
def test_hosts_in_subnet():
|
||||||
|
|||||||
Reference in New Issue
Block a user