使用公网的查询网页抓爬方式
from bs4 import BeautifulSoup
import requests
mac="88-46-04-46-75-34"
url="https://mac.bmcx.com/%s__mac/" % mac
html=requests.get(url,verify=False).content
html=html.decode('utf-8')
html=BeautifulSoup(html,features="html.parser")
tr=html.select("#main_content table td table tr")
for row in tr:
if "组织名称" in row.text:
td=row.select("td")
print(td[1].text)
使用MAC字典
字典下载地址:https://standards-oui.ieee.org/
import re
mac={}
f=open("../mac.txt",mode='r',encoding='utf-8')
stream=f.read()
pattern="(\S+)\s+\(hex\)\s+([^\n]+)"
pattern=re.compile(pattern)
search=pattern.findall(stream)
for s in search:
mac[s[0]]=s[1]
def get(m):
m=m[:8]
if m in mac.keys():
return mac[m]
else:
return "未知"