前言:
这里获取的是网卡的设备名称然后通过设备名称判断网卡类型,如无线网卡、有线网卡、虚拟网卡,其他网卡(如vpn客户端软件);使用如下代码打包后的程序可运行于win7、win10、win11系统;Python版本为3.8.9;因为工作中临时用到,就随手写的,所以代码规范没有太注意,看不懂的可以打断点分析,不过相信大家都能看的,确实非常简单,需要其他信息的在此基础上自行修改就行。
源码:
# -*- coding: utf-8 -*-
'''
需要的数据:
Wmic Path Win32_NetworkAdapterConfiguration get IPAddress,Index
Wmic Path Win32_NetworkAdapter get productname,Index
以上是获取当前活动网卡及网卡信息的两条命令!可用cmd或Powershell运行。
'''
import subprocess
import re
import os
# ret, val = subprocess.getstatusoutput(r"Wmic Path Win32_NetworkAdapter get GUID,MACAddress,NetEnabled,productname,Index")
ret, val = subprocess.getstatusoutput(r"Wmic Path Win32_NetworkAdapterConfiguration get Index")
# print(ret)
#print(val)
list1=val.split("\n\n") # 每个一行中间相隔2个换行!
list1.pop() # 去除最后一个无用的元素
#print(list1)
ret1, val1 = subprocess.getstatusoutput(r"Wmic Path Win32_NetworkAdapterConfiguration get IPAddress")
# print(ret)
#print(val1)
list2=val1.split("\n\n") # 每个一行中间相隔2个换行!
list2

该Python脚本用于获取Windows系统(包括Win7、Win10、Win11)中网络适配器的类型,如无线、有线或虚拟,并列出活动网卡的IP地址和产品名称。它使用WMI(WindowsManagementInstrumentation)命令来收集信息,包括`Win32_NetworkAdapterConfiguration`和`Win32_NetworkAdapter`的相关数据。
最低0.47元/天 解锁文章
947

被折叠的 条评论
为什么被折叠?



