Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows下获取MAC地址得到的结果与实际不符 #1

Open
StudyCat404 opened this issue Dec 13, 2019 · 0 comments
Open

windows下获取MAC地址得到的结果与实际不符 #1

StudyCat404 opened this issue Dec 13, 2019 · 0 comments

Comments

@StudyCat404
Copy link

StudyCat404 commented Dec 13, 2019

源代码是

def getMac(ip):
	try:
		result = os.popen('arp -a '+ip)    
		data = result.read()
		mac = re.findall(r"\b([0-9a-fA-F]{2})\b", data)
		if mac!=None:
			return mac[0]+"-"+mac[1]+"-"+mac[2]+"-"+mac[3]+"-"+mac[4]+"-"+mac[5]
		return ""
	except:
		pass
		return ""

改成这样可行

def getMac(ip):
	try:
		result = os.popen('arp -a '+target)    
		data = result.read()
		mac = re.findall("(([a-fA-F0-9]{2}[:-]){5}[a-fA-F0-9]{2})", data)
		if mac!=None:
			return mac[0][0]
		return ""
	except:
		return ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant