kyan001 / ping3

Pure Python3 version of ICMP ping, shipped with command-line command.
MIT License
324 stars 56 forks source link

ping OK but src ip not equal ping ip #82

Open varanius85 opened 2 months ago

varanius85 commented 2 months ago

Linux ping result: root@support:~# ping 10.254.237.128 PING 10.254.237.128 (10.254.237.128) 56(84) bytes of data. ^C --- 10.254.237.128 ping statistics --- 4 packets transmitted, 0 received, 100% packet loss, time 3005ms

ping3 result: root@support:~# ping3 -D -c1 10.254.237.128 [DEBUG] Ping3 Version: 4.0.4 [DEBUG] LOGGER: <Logger ping3 (DEBUG)> [DEBUG] Function called: verbose_ping(10.254.237.128, {'count': 1, 'ttl': 64, 'timeout': 4, 'size': 56, 'interval': 0, 'interface': '', 'src_addr': ''}) [DEBUG] Function called: ping(10.254.237.128, {'seq': 0, 'ttl': 64, 'timeout': 4, 'size': 56, 'interface': '', 'src_addr': '', 'unit': 'ms'}) [DEBUG] Function called: send_one_ping({'sock': <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 1)>, 'dest_addr': '10.254.237.128', 'icmp_id': 15384, 'seq': 0, 'size': 56}) [DEBUG] Destination address: '10.254.237.128' [DEBUG] Destination IP address: 10.254.237.128 [DEBUG] Sent ICMP header: {'type': 8, 'code': 0, 'checksum': 859, 'id': 15384, 'seq': 0} [DEBUG] Sent ICMP payload: b"A\xd9\xb7\x9f'\xc1\xf7\xb2QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" [DEBUG] Function returned: send_one_ping -> None [DEBUG] Function called: receive_one_ping({'sock': <socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_RAW, proto=1, laddr=('0.0.0.0', 1)>, 'icmp_id': 15384, 'seq': 0, 'timeout': 4}) [DEBUG] Timeout time: Mon Sep 9 07:42:11 2024 (1725856931.031494) [DEBUG] Timeout left: 4.00s [DEBUG] Received time: Mon Sep 9 07:42:07 2024 (1725856927.0354893)) [DEBUG] Received IP header: {'version': 69, 'tos': 0, 'len': 84, 'id': 40757, 'flags': 16384, 'ttl': 251, 'protocol': 1, 'checksum': 5575, 'src_addr': '192.168.254.241', 'dest_addr': '10.0.1.18'} [DEBUG] Received ICMP header: {'type': 0, 'code': 0, 'checksum': 2907, 'id': 15384, 'seq': 0} [DEBUG] Received ICMP payload: b"A\xd9\xb7\x9f'\xc1\xf7\xb2QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ" [DEBUG] Received sent time: Mon Sep 9 07:42:07 2024 (1725856927.0307431) [DEBUG] Function returned: receive_one_ping -> 0.004746198654174805 [DEBUG] Function returned: ping -> 4.746198654174805 ping '10.254.237.128' ... 4ms [DEBUG] Function returned: verbose_ping -> None

In answer 'src_addr': '192.168.254.241' not equal ping ip '10.254.237.128' It's ping FALSE, but ping3 - TRUE

kyan001 commented 2 months ago

Hi,

Thank you for the feedback.

Based on the log, the src address is written into the IP header of the response, which is not controlled by ping3, ping3 only reads this address. Here are some possible reasons for the issue:

  1. ICMP Redirects: In certain network configurations, a router might redirect your ping request to a different IP address (in this case, 192.168.254.241) and reply on behalf of the original destination (10.254.237.128). This can happen due to a misconfiguration in the network routing or because the router is intentionally set up to handle requests this way.

  2. NAT (Network Address Translation): If your network uses NAT, the IP address 10.254.237.128 might be translated to 192.168.254.241 in the response, which is why the source IP of the reply doesn’t match the one you initially pinged.

Kyan