Created
July 8, 2013 06:32
-
-
Save azhai/5946645 to your computer and use it in GitHub Desktop.
Python获得物理网卡地址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
#CPython | |
def get_mac_addr(): | |
""" 获得本机网卡物理地址 """ | |
import uuid | |
node = uuid.getnode() | |
mac = uuid.UUID(int=node) | |
addr = mac.hex[-12:] | |
return addr | |
#IronPyton | |
from System.Net.NetworkInformation import NetworkInterface, NetworkInterfaceType | |
def getMacAddress(): | |
for netcard in NetworkInterface.GetAllNetworkInterfaces(): | |
if netcard.NetworkInterfaceType == NetworkInterfaceType.Ethernet: | |
return netcard.GetPhysicalAddress().ToString() | |
return "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment