예제 #1
0
 def getIpAddress(self, iface): # getIpAddress('eth0')
     if platform.system == "Linux" and fcntl_module_exists == True:
         s = socket(AF_INET, SOCK_DGRAM)
         ipAddr  =  inet_ntoa(fcntl_module.ioctl(s.fileno(), 0x8915, struct.pack('256s', iface[:15]))[20:24])
         return str(ipAddr)
     else:   # on windows
         ipAddr = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1]
         return str(ipAddr)
예제 #2
0
def get_current_ip():
    import socket
    ip = (([
        ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
        if not ip.startswith("127.")
    ] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close())
           for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]])
          + ["no IP found"])[0]
    return ip
예제 #3
0
 def getIpAddress(self, iface):  # getIpAddress('eth0')
     if platform.system == "Linux" and fcntl_module_exists == True:
         s = socket(AF_INET, SOCK_DGRAM)
         ipAddr = inet_ntoa(
             fcntl_module.ioctl(s.fileno(), 0x8915,
                                struct.pack('256s', iface[:15]))[20:24])
         return str(ipAddr)
     else:  # on windows
         ipAddr = [
             ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]
             if not ip.startswith("127.")
         ][:1]
         return str(ipAddr)
예제 #4
0
def get_current_ip():
    import socket
    ip = (([ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")] or [[(s.connect(("8.8.8.8", 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) + ["no IP found"])[0]
    return ip