我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用socket.if_nameindex()。
def get_if_list(): #return [ i[1] for i in socket.if_nameindex() ] return netifaces.interfaces()
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)