ATTENTION: socket.getaddrinfo() resolves to randon false IP Addresses



  • Pycom Management and Technical Personnel,

    I see this problem posted multiple times in the LoPy forum with no guidance or resolution provided back to your customers & users. So I'm creating another one hoping to get some attention.

    This is a fundamental feature of your product that you provide example code for and should work correctly.

    Why is this happening?

    Is this a BUG or a CONFIG ISSUE?

    PROBLEM: socket.getaddrinfo() resolves incorrectly, giving random incorrect IPv4 IP address, using either of my DNS servers. Tried with URL's micropython.org & google.com

    (sysname='LoPy', nodename='LoPy', release='1.0.0.b1', version='v1.8.6-251-g2fb950d on 2016-12-16', machine='LoPy with ESP32')
    >>> wlan.ifconfig()
    ('10.0.0.36', '255.255.255.0', '10.0.0.1', '75.75.75.75')
    >>> import socket
    >>> addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
    >>> s = socket.socket()
    >>> s.connect(addr)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 113] EHOSTUNREACH
    >>> print(addr)
    ('94.137.14.128', 80)<-------THIS IS INCORRECT IP ADDRESS FOR micropython.org
    
    ----------------------------------------------------------------------------------
    
    >>> wlan.ifconfig(config=('10.0.0.36', '255.255.255.0', '10.0.0.1', '76.76.76.76'))
    >>> wlan.ifconfig()
    ('10.0.0.36', '255.255.255.0', '10.0.0.1', '76.76.76.76')
    >>> addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
    >>> s = socket.socket()
    >>> s.connect(addr)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: [Errno 113] EHOSTUNREACH
    >>> print(addr)
    ('156.16.8.3', 80)<-------THIS IS INCORRECT IP ADDRESS FOR micropython.org
    

    HOWEVER: When I use the same code on my Ubuntu 16.04 / Python on the same WIFI LAN it resolves the IP address successfully.

    rdixey@RND-SP3:~$ nmcli device show wlp1s0 | grep IP4.DNS
    IP4.DNS[1]:                             75.75.75.75
    IP4.DNS[2]:                             75.75.76.76
    rdixey@RND-SP3:~$ python
    Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
    [GCC 5.4.0 20160609] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
    >>> s = socket.socket()
    >>> s.connect(addr)
    >>> print(addr)
    ('176.58.119.26', 80)<-------THIS IS CORRECT IP ADDRESS FOR micropython.org
    


  • I confirm problem solved by use of the DHCP instead of static parameters in wlan.ifconfig.
    If you need a static address it seems that the sequence :
    wlan.ifconfig(static parameters) (by example in boot.py)
    wlan.ifconfig(dhcp)
    wlan.ifconfig(static parameters)
    correctly initialize the name resolver (the DNS server must be the same for the static and dhcp config).
    tested with 1.0.0b2



  • @rdixey thanks for the feedback. We'll do our best to solve the static IP problem asap.

    Cheers,
    Daniel



  • Daniel, I reconfigured the LoPy and router for DHCP and the socket connection works just fine. I would not have known this without your reply since I did search the forum and did not find this info there. Many Thanks :)



  • Hello @rdixey this is an issue when using static IP configurations and we are trying to resolve it with Espressif. Are you able to use DHCP in the meantime? Thanks.

    Cheers,
    Daniel


Log in to reply
 

Pycom on Twitter