ValentinBELYN / icmplib

Easily forge ICMP packets and make your own ping and traceroute.
GNU Lesser General Public License v3.0
267 stars 45 forks source link

icmplib fails to ping hostnames that only resolve to AAAA entries #21

Closed nbarrientos closed 3 years ago

nbarrientos commented 3 years ago
# docker-compose exec home-assistant bash
bash-5.0# /usr/local/bin/python3
Python 3.8.5 (default, Sep 10 2020, 14:23:57)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from icmplib import ping
>>> ping('192.168.1.1')
<Host [192.168.1.1]>
>>> host = ping('192.168.1.1')
>>> host.is_alive
True
>>> host = ping('foo:bar:baz:1::101')
>>> host.is_alive
True
>>> host = ping('only-aaaa.example.org')
>>> host.is_alive
False
bash-5.0# ping6 -c 1 only-aaaa.example.org
PING only-aaaa.example.org (foo:bar:baz:1::101): 56 data bytes
64 bytes from foo:bar:baz:1::101: seq=0 ttl=62 time=0.981 ms

You can probably reproduce the same with ipv6.google.com:

bash-5.0# host ipv6.google.com
ipv6.google.com is an alias for ipv6.l.google.com.
ipv6.l.google.com has IPv6 address 2a00:1450:400a:800::200e
bash-5.0# ping6 ipv6.google.com
PING ipv6.google.com (2a00:1450:400a:802::200e): 56 data bytes
64 bytes from 2a00:1450:400a:802::200e: seq=0 ttl=111 time=10.882 ms
^C
--- ipv6.google.com ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 10.882/10.882/10.882 ms
bash-5.0# pip list | grep icmplib
icmplib                          1.1.3
bash-5.0# python3
Python 3.8.5 (default, Sep 10 2020, 14:23:57)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from icmplib import ping
>>> host = ping('ipv6.google.com')
>>> host.is_alive
False
>>>

Issue originally reported here: https://github.com/home-assistant/core/issues/40232#issuecomment-704425584

nbarrientos commented 3 years ago

I can reproduce it with the latest version available:

(icmplib) root@x:~# pip list | grep icmplib
icmplib       1.2.1
(icmplib) root@x:~# python3
Python 3.8.6 (default, Sep 25 2020, 09:36:53)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from icmplib import ping
>>> host = ping('2a00:1450:400a:802::200e')
>>> host.is_alive
True
>>> host = ping('ipv6.google.com')
>>> host.is_alive
False
>>>
ValentinBELYN commented 3 years ago

Hi, I confirm the problem. FQDN resolution currently only works for IPv4 addresses. I will look into it to correct it as soon as possible. Thank you for reporting this issue :)

ValentinBELYN commented 3 years ago

icmplib 1.2.2 is available! This release adds DNS resolution for IPv6 addresses and improves overall performance. Can you update the library and tell me if your problem persists?

nbarrientos commented 3 years ago

Ça roule, merci! :)

~/venvs $ source icmplib/bin/activate
~/venvs $ pip install --upgrade icmplib
Collecting icmplib
  Downloading icmplib-1.2.2-py3-none-any.whl (26 kB)
Installing collected packages: icmplib
  Attempting uninstall: icmplib
    Found existing installation: icmplib 1.2.1
    Uninstalling icmplib-1.2.1:
      Successfully uninstalled icmplib-1.2.1
Successfully installed icmplib-1.2.2
~/venvs $ sudo icmplib/bin/python3
...
Type "help", "copyright", "credits" or "license" for more information.
>>> from icmplib import ping
>>> host = ping('ipv6.google.com')
>>> host.is_alive
True