Use icmplib instead of pythonping
This commit is contained in:
@@ -2,19 +2,22 @@
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
import ipaddress
|
||||
from pythonping import ping
|
||||
import socket
|
||||
from typing import List
|
||||
from colorama import init, Fore
|
||||
from icmplib import async_multiping, ping, multiping
|
||||
|
||||
init()
|
||||
GREEN = Fore.GREEN
|
||||
RESET = Fore.RESET
|
||||
GRAY = Fore.LIGHTBLACK_EX
|
||||
|
||||
def are_alive(addresses: List[str]) -> List[str]:
|
||||
hosts = multiping(addresses)
|
||||
return [ host.address for host in hosts if host.is_alive ]
|
||||
|
||||
def is_host_alive(host: str) -> bool:
|
||||
if ping(host, timeout=1, count=1).success():
|
||||
if ping(host, timeout=1, count=1).is_alive:
|
||||
return True
|
||||
else:
|
||||
print(f"{GRAY}{host:15} is not alive {RESET}")
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# SPDX-FileCopyrightText: 2022-present U.N. Owen <void@some.where>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
import asyncio
|
||||
import click
|
||||
from pscanner import is_port_open, is_subnet, hosts_in_subnet, is_host_alive
|
||||
from pscanner import are_alive, async_are_alive, is_port_open, is_subnet, hosts_in_subnet, is_host_alive
|
||||
from ..__about__ import __version__
|
||||
|
||||
|
||||
@@ -16,8 +17,12 @@ from ..__about__ import __version__
|
||||
@click.pass_context
|
||||
def pscanner(ctx: click.Context, host, port):
|
||||
if is_subnet(host):
|
||||
for ip in hosts_in_subnet(host):
|
||||
if is_host_alive(str(ip)):
|
||||
hosts = [ str(_) for _ in hosts_in_subnet(host) ]
|
||||
print(f"pinging {len(hosts)} hosts")
|
||||
#alive_hosts = asyncio.run(async_are_alive(hosts), debug=True)
|
||||
alive_hosts = are_alive(hosts)
|
||||
print(f"found {len(alive_hosts)} alive")
|
||||
for ip in alive_hosts:
|
||||
is_port_open(str(ip), port)
|
||||
else:
|
||||
if is_host_alive(host):
|
||||
|
||||
@@ -25,7 +25,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"click",
|
||||
"pythonping"
|
||||
"icmplib"
|
||||
]
|
||||
dynamic = ["version"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user