code: def local_ip():
      
      ip = socket.gethostbyname(socket.gethostname())
      if ip.startswith('127.'):
          # Check eth0, eth1, eth2, en0, ...
          interfaces = [
              i + str(n) for i in ("eth", "en", "wlan") for n in xrange(3)
          ]  # :(
          for interface in interfaces:
              try:
                  ip = interface_ip(interface)
                  break
              except IOError:
                  pass
      return ip
docs: Get the local network IP of this machine