Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取python中移动宽带调制解调器的MAC地址_Python_Networking_Pyqt4_Mac Address_Ppp - Fatal编程技术网

获取python中移动宽带调制解调器的MAC地址

获取python中移动宽带调制解调器的MAC地址,python,networking,pyqt4,mac-address,ppp,Python,Networking,Pyqt4,Mac Address,Ppp,我想获取Linux上网络接口的MAC地址。我将Python与PyQt4模块一起使用。当我运行此代码时: form PyQt4.QtNetwork import * def getinfo(): all_info = QNetworkInterface().allInterfaces() for interface in all_info: print interface.hardwareAddress()," ",interface.humanReadableName()

我想获取Linux上网络接口的MAC地址。我将Python与PyQt4模块一起使用。当我运行此代码时:

form PyQt4.QtNetwork import *
def getinfo():
  all_info = QNetworkInterface().allInterfaces()
  for interface in all_info:
        print interface.hardwareAddress()," ",interface.humanReadableName()
我把这个拿出来:

00:00:00:00:00:00   lo
00:26:2D:8C:8F:B3   eth3
F0:7B:CB:3B:82:2B   wlan3
  ppp0

它适用于
eth3
wlan3
,但在我的移动宽带调制解调器上运行的
ppp0
上,MAC地址不会出现。

ppp
不使用MAC(硬件)地址:

一般来说,如果您正在寻找Python中的网络接口管理,那么只需看看。它设计为在MacOSX、Linux和Windows上跨平台

>>> import netifaces as ni
>>> ni.interfaces()
['lo', 'eth0', 'eth1', 'vboxnet0', 'dummy1']
>>> ni.ifaddresses('eth0')
{17: [{'broadcast': 'ff:ff:ff:ff:ff:ff', 'addr': '00:02:55:7b:b2:f6'}], 2: [{'broadcast': '24.19.161.7', 'netmask': '255.255.255.248', 'addr': '24.19.161.6'}], 10: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::202:55ff:fe7b:b2f6%eth0'}]}
>>> 
>>> ni.ifaddresses.__doc__
'Obtain information about the specified network interface.\n\nReturns a dict whose keys are equal to the address family constants,\ne.g. netifaces.AF_INET, and whose values are a list of addresses in\nthat family that are attached to the network interface.'
>>> # for the IPv4 address of eth0
>>> ni.ifaddresses('eth0')[2][0]['addr']
'24.19.161.6'
用于索引协议的数字来自
/usr/include/linux/socket.h
(在linux中)

>>> import netifaces as ni
>>> ni.interfaces()
['lo', 'eth0', 'eth1', 'vboxnet0', 'dummy1']
>>> ni.ifaddresses('eth0')
{17: [{'broadcast': 'ff:ff:ff:ff:ff:ff', 'addr': '00:02:55:7b:b2:f6'}], 2: [{'broadcast': '24.19.161.7', 'netmask': '255.255.255.248', 'addr': '24.19.161.6'}], 10: [{'netmask': 'ffff:ffff:ffff:ffff::', 'addr': 'fe80::202:55ff:fe7b:b2f6%eth0'}]}
>>> 
>>> ni.ifaddresses.__doc__
'Obtain information about the specified network interface.\n\nReturns a dict whose keys are equal to the address family constants,\ne.g. netifaces.AF_INET, and whose values are a list of addresses in\nthat family that are attached to the network interface.'
>>> # for the IPv4 address of eth0
>>> ni.ifaddresses('eth0')[2][0]['addr']
'24.19.161.6'
#define AF_INET         2       /* Internet IP Protocol         */
#define AF_INET6        10      /* IP version 6                 */
#define AF_PACKET       17      /* Packet family                */