I am new here and just learning python. I need help to get the right mac-address of my network card in windows using python. I tried to search, and found these :
If I run "ipconfig /all" from command prompt, I get this :
Windows-IP-Konfiguration
Hostname . . . . . . . . . . . . : DESKTOP-CIRBA63
Primäres DNS-Suffix . . . . . . . :
Knotentyp . . . . . . . . . . . . : Hybrid
IP-Routing aktiviert . . . . . . : Nein
WINS-Proxy aktiviert . . . . . . : Nein
Ethernet-Adapter Ethernet:
Verbindungsspezifisches DNS-Suffix:
Beschreibung. . . . . . . . . . . : Realtek PCIe FE Family Controller
Physische Adresse . . . . . . . . : 32-A5-2C-0B-14-D9
DHCP aktiviert. . . . . . . . . . : Nein
Autokonfiguration aktiviert . . . : Ja
IPv4-Adresse . . . . . . . . . . : 192.168.142.35(Bevorzugt)
Subnetzmaske . . . . . . . . . . : 255.255.255.0
Standardgateway . . . . . . . . . : 192.168.142.1
DNS-Server . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS über TCP/IP . . . . . . . : Deaktiviert
Ethernet-Adapter Ethernet 2:
Medienstatus. . . . . . . . . . . : Medium getrennt
Verbindungsspezifisches DNS-Suffix:
Beschreibung. . . . . . . . . . . : Norton Security Data Escort Adapter
Physische Adresse . . . . . . . . : 00-CE-35-1B-77-5A
DHCP aktiviert. . . . . . . . . . : Ja
Autokonfiguration aktiviert . . . : Ja
Tunneladapter isatap.{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}:
Medienstatus. . . . . . . . . . . : Medium getrennt
Verbindungsspezifisches DNS-Suffix:
Beschreibung. . . . . . . . . . . : Microsoft ISATAP Adapter
Physische Adresse . . . . . . . . : 00-00-00-00-00-00-00-A0
DHCP aktiviert. . . . . . . . . . : Nein
Autokonfiguration aktiviert . . . : Ja
I need to get the mac address of my Realtek network card (32-A5-2C-0B-14-D9), not the one created by Norton or windows tunneling.
Python gave me another result of mac address if i am using :
"uuid.getnode() or "getmac"
I think the best way is to get the output of
"ipconfig /all"
,
looking at "Realtek" at "Beschreibung" and then get the "Physische Adresse" information to get my real mac address.
How to do this in python on windows ? Any help is appreciated. Thanks in advance.
You can retrieve the windows interface information using wmic in XML format, and then convert the xml to a dict. From the resulting dict you can gather any needed information:
This function will return a list of dicts, the desired information can be returned from the resulting dicts:
the python3 script below is based on the Stephen Rauch one (thanks for the wmic utility pointer it's really handy)
it retrieves only the IP and active interfaces from the computer, handles fields with multiple values (several ips/masks or gateways on one nic), creates IPv4Iinterface or v6 python objects from ip/mask, and ouputs a list with one dict per nic.
import it or use it from a cmd prompt :
will output something like :
tested with windows10. I have some doubts about the mac adress field, with VM or spoofing cases for example, it seems wmic returns one string only, and not an array.