當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.if_nameindex方法代碼示例

本文整理匯總了Python中socket.if_nameindex方法的典型用法代碼示例。如果您正苦於以下問題:Python socket.if_nameindex方法的具體用法?Python socket.if_nameindex怎麽用?Python socket.if_nameindex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socket的用法示例。


在下文中一共展示了socket.if_nameindex方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: local_ip4_addr_list

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import if_nameindex [as 別名]
def local_ip4_addr_list():
    """Return a set of IPv4 address
    """
    assert os.name != 'nt', 'Do not support Windows rpc yet.'
    nic = set()
    for if_nidx in socket.if_nameindex():
        name = if_nidx[1]
        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            ip_of_ni = fcntl.ioctl(sock.fileno(),
                                   0x8915,  # SIOCGIFADDR
                                   struct.pack('256s', name[:15].encode("UTF-8")))
        except OSError as e:
            if e.errno == 99: # EADDRNOTAVAIL
                print("Warning!",
                      "Interface: {}".format(name),
                      "IP address not available for interface.",
                      sep='\n')
                continue
            else:
                raise e

        ip_addr = socket.inet_ntoa(ip_of_ni[20:24])
        nic.add(ip_addr)
    return nic 
開發者ID:dmlc,項目名稱:dgl,代碼行數:27,代碼來源:rpc_client.py

示例2: _local_ip4_addr_list

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import if_nameindex [as 別名]
def _local_ip4_addr_list(self):
        """Return a set of IPv4 address
        """
        nic = set()

        for ix in socket.if_nameindex():
            name = ix[1]
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            ip = socket.inet_ntoa(fcntl.ioctl(
                s.fileno(),
                0x8915,  # SIOCGIFADDR
                struct.pack('256s', name[:15].encode("UTF-8")))[20:24])
            nic.add(ip)

        return nic 
開發者ID:dmlc,項目名稱:dgl,代碼行數:17,代碼來源:dis_kvstore.py

示例3: local_ip4_addr_list

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import if_nameindex [as 別名]
def local_ip4_addr_list():
    """Return a set of IPv4 address
    """
    nic = set()

    for ix in socket.if_nameindex():
        name = ix[1]
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        ip = socket.inet_ntoa(fcntl.ioctl(
            s.fileno(),
            0x8915,  # SIOCGIFADDR
            struct.pack('256s', name[:15].encode("UTF-8")))[20:24])
        nic.add(ip)

    return nic 
開發者ID:dmlc,項目名稱:dgl,代碼行數:17,代碼來源:kvclient.py

示例4: testInterfaceNameIndex

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import if_nameindex [as 別名]
def testInterfaceNameIndex(self):
        interfaces = socket.if_nameindex()
        for index, name in interfaces:
            self.assertIsInstance(index, int)
            self.assertIsInstance(name, str)
            # interface indices are non-zero integers
            self.assertGreater(index, 0)
            _index = socket.if_nametoindex(name)
            self.assertIsInstance(_index, int)
            self.assertEqual(index, _index)
            _name = socket.if_indextoname(index)
            self.assertIsInstance(_name, str)
            self.assertEqual(name, _name) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:15,代碼來源:test_socket.py

示例5: get_if_list

# 需要導入模塊: import socket [as 別名]
# 或者: from socket import if_nameindex [as 別名]
def get_if_list():
      #return [ i[1] for i in socket.if_nameindex() ]
      return netifaces.interfaces() 
開發者ID:phaethon,項目名稱:kamene,代碼行數:5,代碼來源:pcapdnet.py


注:本文中的socket.if_nameindex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。