Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

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

    Scheduled Pinned Locked Moved LoPy
    5 Posts 3 Posters 1.9k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rdixey
      last edited by

      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
      
      1 Reply Last reply Reply Quote 0
      • D Offline
        daniel
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • R Offline
          rdixey
          last edited by

          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 :)

          1 Reply Last reply Reply Quote 0
          • D Offline
            daniel
            last edited by

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

            Cheers,
            Daniel

            1 Reply Last reply Reply Quote 0
            • P Offline
              PCA
              last edited by

              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

              1 Reply Last reply Reply Quote 0

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom