diff --git a/BlocklyPropClient.py b/BlocklyPropClient.py index 4a286df..60f1703 100644 --- a/BlocklyPropClient.py +++ b/BlocklyPropClient.py @@ -10,7 +10,6 @@ import os import ip import sys -import time import BlocklyServer __author__ = 'Michel & Vale' diff --git a/ip.py b/ip.py index 5ea3788..e147e24 100644 --- a/ip.py +++ b/ip.py @@ -1,8 +1,8 @@ -__author__ = 'Michel' - import os import socket +__author__ = 'Michel' + if os.name != "nt": import fcntl import struct @@ -12,8 +12,15 @@ def get_interface_ip(if_name): return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', if_name[:15]))[20:24]) + def get_lan_ip(): - ip = socket.gethostbyname(socket.gethostname()) + # Find the client's IP address + try: + ip = socket.gethostbyname(socket.gethostname()) + except socket.error as msg: + print msg.message + ip = "0.0.0.0" + if ip.startswith("127.") and os.name != "nt": interfaces = [ "eth0", @@ -26,10 +33,11 @@ def get_lan_ip(): "ath1", "ppp0", ] + for if_name in interfaces: try: ip = get_interface_ip(if_name) break except IOError: pass - return ip \ No newline at end of file + return ip