Raspberry LCD IP display format
Question: I'm working on a little project with a Raspberry Pi, and I need to display the
IP adress of the PI on an LCD screen.

I followed this tutorial : <https://learn.adafruit.com/drive-a-16x2-lcd-
directly-with-a-raspberry-pi/python-code>

It seems to work fine, however there is a problem displaying the IP. Instead
of displaying "192.168.0.68", it shows "fe80::779b:a7a1:9282:f4d5". It shows
the time just fine ("Sep 19 18:20:41").

Being new to programming, I couldn't find the problem, so here I am asking for
help

Thanks in advance !


Answer: I found the `netifaces` package to be useful for obtaining the IP address. The
link below explains well about its basic usage

<https://pypi.python.org/pypi/netifaces>

Below is an example to obtain the ip address in the python interpreter.

    
    
    >>>import netifaces
    >>>addr = netifaces.ifaddresses('en1')
    >>>addr
    {18: [{'addr': 'e4:ce:8f:30:98:0c'}], 2: [{'broadcast': '192.168.1.255', 'addr': '192.168.1.22', 'netmask': '255.255.255.0'}], 30: [{'addr': 'fe80::e6ce:8fff:fe30:980c%en1', 'netmask': 'ffff:ffff:ffff:ffff::'}]}
    >>>addr[netifaces.AF_INET][0]['addr']
    '192.168.1.22'
    

Note: I use `'en1'` because I'm on a Mac. In the Pi typically this would be
`'eth0'`

