mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 19:12:03 +03:00
make _resolve async to avoid blocking the event loop
This commit is contained in:
parent
e4c51546ba
commit
329ff15e74
1 changed files with 5 additions and 3 deletions
|
|
@ -53,9 +53,11 @@ async def tcp_connect_rtt(
|
||||||
return (time.perf_counter() - began) * 1000.0
|
return (time.perf_counter() - began) * 1000.0
|
||||||
|
|
||||||
|
|
||||||
def _resolve(host: str) -> str | None:
|
async def _resolve(host: str) -> str | None:
|
||||||
try:
|
try:
|
||||||
return socket.getaddrinfo(host, None, proto=socket.IPPROTO_TCP)[0][4][0]
|
loop = asyncio.get_running_loop()
|
||||||
|
res = await loop.getaddrinfo(host, None, proto=socket.IPPROTO_TCP)
|
||||||
|
return res[0][4][0]
|
||||||
except (OSError, IndexError):
|
except (OSError, IndexError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -87,7 +89,7 @@ async def ping_host(
|
||||||
backend: str,
|
backend: str,
|
||||||
source_ip: str | None = None,
|
source_ip: str | None = None,
|
||||||
) -> PingResult:
|
) -> PingResult:
|
||||||
resolved = _resolve(host)
|
resolved = await _resolve(host)
|
||||||
if backend in ("icmp_win", "icmp_dgram", "icmp_raw"):
|
if backend in ("icmp_win", "icmp_dgram", "icmp_raw"):
|
||||||
try:
|
try:
|
||||||
samples = await _icmp_samples(host, count, interval, timeout, backend, source_ip)
|
samples = await _icmp_samples(host, count, interval, timeout, backend, source_ip)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue