python判断是否连接wifi_python操作linux连接wifi,查看wifi连接状态方法

营养咨询python判断是否连接wifi_python操作linux连接wifi,查看wifi连捕鼠弓
aod接状态⽅法
# 查询所有物理⽹卡def_query_net_card_info(if_name):
net_card_info={"mac": "","type": "eth","ip": "","netmask": "",
}try:
池州学院学报
net_info=netifaces.ifaddresses(if_name)exceptValueError:
<("No such interface: %s" %if_name)returnnet_card_info#如果为⽆线⽹卡,将修改⽹卡类型为wlan
if if_name d_excute("iw dev | awk '$1==\"Interface\" {print $2}'"):
net_card_info["type"] = "wlan"net_card_info["mac"] = net_info[netifaces.AF_LINK][0]["addr"].upper()
ipv4_info=(netifaces.AF_INET)ifipv4_info:
net_card_info["ip"] = ipv4_info[0]["addr"]
net_card_info["netmask"] = ipv4_info[0]["netmask"]returnnet_card_info
@staticmethoddefquery_net_cards():"""{
"enp2s0": // 接⼝名称
{
"mac": "98:FA:9B:99:E5:6A", // MAC地址
"type": "eth", // 接⼝类型,eth-有线⽹卡, wlan-⽆线⽹卡
"ip": "192.168.2.90", // 接⼝当前IP
"netmask": "255.255.255.0", // 接⼝掩码
"dns":"192.168.2.1", // dns服务器ip
"gateway": "192.168.2.1" // ⽹管地址
},
"wlan0":
{
"mac": "98:FA:9B:99:E5:6A", // MAC地址
"type": "wlan", // 接⼝类型,eth-有线⽹卡, wlan-⽆线⽹卡
抗弯强度
"ip": "", // 接⼝当前IP
"netmask": "", // 接⼝掩码
"dns":"192.168.2.1", // dns服务器ip
滇西1994
"gateway": "192.168.2.1" // ⽹管地址
}
}"""net_cards=dict()#获取所有物理⽹卡名称
command = "ls -d /sys/class/net/*/device | cut -d/ -f5"d_excute(command)#获取dns服务器ip
dns_path = '/f'dns_list=[]ists(dns_path):
dns_list= d_excute("cat %s|grep ^nameserver|awk '{print $2}'" % dns_path, b_print=False)#获取⽹管地址gateways = netifaces.gateways().get('default').get(netifaces.AF_INET)for interface ininterfaces:
net_card= Network._query_net_card_info(if_name=interface)
net_card["dns"] = dns_list if dns_list else ""net_card["gateway"] = gateways[0] if gateways else
""net_cards[interface]=net_cardreturn net_cards

本文发布于:2024-09-23 01:22:54,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/349554.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:连接   获取   物理   类型
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议