From 3dd6e660c3e7afa485cbdd3768926d970c2d3464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=88=D1=83=D1=82=D0=BA=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB?= Date: Sun, 13 Jul 2025 17:12:47 +0700 Subject: [PATCH 1/3] False replies have been fixed --- .idea/.gitignore | 8 ++++++++ aioping/__init__.py | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/aioping/__init__.py b/aioping/__init__.py index 9221d91..27471da 100644 --- a/aioping/__init__.py +++ b/aioping/__init__.py @@ -138,7 +138,7 @@ def checksum(buffer): return answer -async def receive_one_ping(my_socket, id_, timeout): +async def receive_one_ping(my_socket, id_, timeout, expected_src_ip): """ receive the ping from the socket. :param my_socket: @@ -151,7 +151,7 @@ async def receive_one_ping(my_socket, id_, timeout): try: async with async_timeout.timeout(timeout): while True: - rec_packet = await loop.sock_recv(my_socket, 1024) + rec_packet, addr = await loop.sock_recvfrom(my_socket, 1024) # No IP Header when unpriviledged on Linux has_ip_header = ( @@ -176,6 +176,9 @@ async def receive_one_ping(my_socket, id_, timeout): if type != ICMP_ECHO_REPLY and type != ICMP6_ECHO_REPLY: continue + if addr[0] != expected_src_ip: + continue + if not has_ip_header: # When unprivileged on Linux, ICMP ID is rewrited by kernel # According to https://stackoverflow.com/a/14023878/4528364 @@ -293,7 +296,7 @@ async def ping(dest_addr, timeout=10, family=None): my_id = uuid.uuid4().int & 0xFFFF await send_one_ping(my_socket, addr, my_id, timeout, family) - delay = await receive_one_ping(my_socket, my_id, timeout) + delay = await receive_one_ping(my_socket, my_id, timeout, addr[0]) my_socket.close() return delay From ca1be9440904efa79488fcdfa48e32ce9444a62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=88=D1=83=D1=82=D0=BA=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB?= Date: Sun, 13 Jul 2025 17:13:45 +0700 Subject: [PATCH 2/3] False replies have been fixed --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28d8e97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.idea/* \ No newline at end of file From b48b404347ae0fdda6452cc968354bc6a9c471ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D1=80=D1=88=D1=83=D1=82=D0=BA=D0=B8=D0=BD=20?= =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB?= Date: Sun, 13 Jul 2025 17:15:48 +0700 Subject: [PATCH 3/3] Remove .idea from git and add to .gitignore --- .gitignore | 3 +-- .idea/.gitignore | 8 -------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 .idea/.gitignore diff --git a/.gitignore b/.gitignore index 28d8e97..9f11b75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -.idea -.idea/* \ No newline at end of file +.idea/ diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml