def get_lan_ip():
    ip = socket.gethostbyname(socket.gethostname())
if ip.startswith('127.') and os.name != 'nt':
    interfaces = ['eth0', 'eth1', 'eth2', 'wlan0', 'wlan1', 'wifi0', 'ath0',
        'ath1', 'ppp0']
Python - Get localhost IP