Raspberry LCD IP display format
<p>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. </p>

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

<p>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"). </p>

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

<p>Thanks in advance !</p>

<p>I found the <code>netifaces</code> package to be useful for obtaining the IP address. The link below explains well about its basic usage</p>

<p><a href="https://pypi.python.org/pypi/netifaces" rel="nofollow">https://pypi.python.org/pypi/netifaces</a></p>

<p>Below is an example to obtain the ip address in the python interpreter.</p>

<pre><code>&gt;&gt;&gt;import netifaces
&gt;&gt;&gt;addr = netifaces.ifaddresses('en1')
&gt;&gt;&gt;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::'}]}
&gt;&gt;&gt;addr[netifaces.AF_INET][0]['addr']
'192.168.1.22'
</code></pre>

<p>Note: I use <code>'en1'</code> because I'm on a Mac. In the Pi typically this would be <code>'eth0'</code></p>

python raspberry-pi ip lcd