Skip to content

Instantly share code, notes, and snippets.

@azhai
Created July 8, 2013 06:32
Show Gist options
  • Save azhai/5946645 to your computer and use it in GitHub Desktop.
Save azhai/5946645 to your computer and use it in GitHub Desktop.
Python获得物理网卡地址
# -*- 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