Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
Created December 8, 2012 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-zhang/4240150 to your computer and use it in GitHub Desktop.
Save mike-zhang/4240150 to your computer and use it in GitHub Desktop.
windows下获取MAC地址(python代码)
# just in windows
import os
var = os.popen("wmic nicconfig get MACAddress").read()
#print var
macList = []
for x in var.split(" \r\n"):
if len(x.strip()) > 0 and x.find("MACAddress"):
if x not in macList:macList.append(x)
for macAddr in macList:print macAddr
raw_input("Press Enter to continue")
# just in windows
import os
var = os.popen("getmac /NH /FO csv").read()
#print var
macList = []
for line in var.split("\n") :
#print line.split(',')[0][1:-1]
macAddrTmp = line.split(',')[0][1:-1]
if macAddrTmp not in macList : macList.append(macAddrTmp)
for macAddr in macList:print macAddr
raw_input("Press Enter to continue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment