1. Got a question or need help troubleshooting? Post to the troubleshooting forum or Search the forums!

Incorrectly-displayed IP address in LCD - Network Status

Discussion in 'Software' started by OutsourcedGuru, Sep 6, 2017.

  1. OutsourcedGuru

    OutsourcedGuru Active Member

    Joined:
    Jun 3, 2017
    Messages:
    752
    Likes Received:
    141
    Throwing this to @mark tomlinson ...

    ~/oprint/local/lib/python2.7/site-packages/RoboLCD/lcd/netconnectd.py

    Code:
    class NetconnectdClient():
        address = '/var/run/netconnectd.sock'
        timeout = 120
    
        def hostname(self):
            return socket.gethostname() + ".local"
    
        def get_ip(self):
            return [l for l in ([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) if l][0][0]
    
    The problem appears to be in that biggest paragraph. Also, there's __init__.py in the same folder:

    Code:
           def generate_ip_screen(self, **kwargs):
                # Misnomer -- Network Status
                def get_network_status():
                    netcon = NetconnectdClient()
                    try:
                        #Determine mode and IP
                        status = netcon._get_status()
                        wifi = status['connections']['wifi']
                        ap = status['connections']['ap']
                        wired = status['connections']['wired']
    
                        if wifi and wired:
                            ssid = status['wifi']['current_ssid']
                            ip = netcon.get_ip()
                            mode = 'Wifi  \"{}\"'.format(ssid)
                            mode += ' and Wired Ethernet'
                        elif wifi:
                            ssid = status['wifi']['current_ssid']
                            ip = netcon.get_ip()
                            mode = 'Wifi  \"{}\"'.format(ssid)
                        elif ap and wired:
                            mode = 'Hotspot mode and Wired Ethernet'
                            ip = '10.250.250.1' + ' , ' + netcon.get_ip()
                        elif ap:
                            mode = 'Hotspot mode'
                            ip = '10.250.250.1'
                        elif wired:
                            mode = 'Wired ethernet'
                            ip = netcon.get_ip()
                        else:
                            mode = 'Neither in hotspot mode or connected to wifi'
                            ip = ''
                        hostname = netcon.hostname()
    
    You'd have to indicate whether or not you also have a wired ethernet connection. That netcon.get_ip() exercises that code listed first above. And since that's failing, then it's just bubbling the wrong information up to the LCD status.

    Dissecting that first large paragraph it looks like:

    1. socket.gethostbyname_ex('serial-number') should return a three-string array in which the [2] is a list of IP addresses (and someone maybe assumed that it's just a single IP address).
    2. if not ip.startswith("127.")][:1] That [:1] suggests that we're looking for all array entries except for the last one. In theory, this is to remove the single 127.0.0.1 loopback address entry bound to one of the cards.
    3. [[(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]. For some reason, they're trying to do a DNS lookup from the Google primary DNS server to look for the socket name. getsockname() is often used to fetch the socket details. Maybe they're making a last-ditch effort of running a local broadcast of some kind.

    That use of a public DNS server for anything is probably just a mistake.
     
  2. OutsourcedGuru

    OutsourcedGuru Active Member

    Joined:
    Jun 3, 2017
    Messages:
    752
    Likes Received:
    141
    Note also the config_yaml.rst file (which may go into creating the first config.yaml perhaps. Not sure if any logic is kicking in from this but from what you indicated, your private IP address range isn't in these:

    Code:
    # If set to true, will automatically log on clients originating from any of the networks defined in
    # "localNetworks" as the user defined in "autologinAs". Defaults to false.
    autologinLocal: true
    
    # The name of the user to automatically log on clients originating from "localNetworks" as. Must
    # be the name of one of your configured users.
    autologinAs: someUser
    
    # A list of networks or IPs for which an automatic logon as the user defined in "autologinAs" will
    # take place. If available OctoPrint will evaluate the "X-Forwarded-For" HTTP header for determining
    # the client's IP address (see https://code.google.com/p/haproxy-docs/wiki/forwardfor on how to
    # configure the sending of this header in HAProxy). Defaults to 127.0.0.0/8 (so basically anything
    # originating from localhost).
    localNetworks:
    - 127.0.0.0/8
    - 192.168.1.0/24
    
     
  3. mark tomlinson

    mark tomlinson ༼ つ ◕_ ◕ ༽つ
    Staff Member

    Joined:
    Feb 21, 2013
    Messages:
    23,912
    Likes Received:
    7,338
    Also will try this post-move :)
    Thanks.
     

Share This Page