I want to get the MAC address for my network interface on Linux. I am using Python with PyQt4 modules. When I run this code:
form PyQt4.QtNetwork import *
def getinfo():
all_info = QNetworkInterface().allInterfaces()
for interface in all_info:
print interface.hardwareAddress()," ",interface.humanReadableName()
I get this outout:
00:00:00:00:00:00 lo
00:26:2D:8C:8F:B3 eth3
F0:7B:CB:3B:82:2B wlan3
ppp0
It works fine with eth3 and wlan3, but with ppp0 which runs on my mobile broadband modem, the MAC address doesn’t appear.
pppdoesn’t use a MAC (hardware) address:In general, if you’re looking for network interface management in Python, look no further than netifaces. It is designed to be cross-platform on Mac OS X, Linux, and Windows.
The numbers used to index protocols are from
/usr/include/linux/socket.h(in Linux)…