I am writing a distributed systems program in python, and in this program I need to know the local ip-address... eg. 168.192.... 10.13..... etc, not 127.0.0.1 or hostname.
I have found following solution on stackoverflow
import socket socket.gethostbyname(socket.gethostname())
When I run this on my Debian jessie laptop, I get 127.0.0.1, however, my friend who is using Fedora on his machine gets the desired ip address when he runs the same script (eg. 168.192..)
I prefer to use the solution above if possible to get the local ip address, because most of the other proposed solutions are either hacks or incredible long...
Is there something I can setup on my Debian jessie laptop such that python will return the correct local ip-address?
- using debian jessie
- python 3
- is connected to network (.. and computer is turned on)... ;)
- /etc/hosts currently contains:
::1 localhost ip6-localhost ip6-loopback