求助 VB6如何获取网卡名称及DNS地址
在网上找了些代码,可以实现获取IP地址,掩码、网关,网卡描述,Mac地址等信息,如何获取网卡名称(本地连接、以太网等),不是网卡描述。还有DNS服务器地址!
程序代码:
Private Sub Form_Load() Set wmiService = GetObject("winmgmts:\\.\root\cimv2") Set Items = wmiService.ExecQuery("Select * From Win32_NetworkAdapter") s = "" For Each objItem In Items If LCase(Left(objItem.PNPDeviceID, 4)) = "pci\" Then Set Its = wmiService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration where Caption='" & objItem.Caption & "'") For Each It In Its If Not IsNull(It.MACAddress) Then n = n + 1 s = s & "网卡" & n & ":" & vbCrLf _ & "网卡名称:" & It.Caption & vbCrLf _ & "物理地址:" & It.MACAddress & vbCrLf & vbCrLf If Not IsNull(It.IPAddress) Then s = Left(s, Len(s) - 2) & "IPv4地址:" & It.IPAddress(0) _ & vbCrLf & "IPv6地址:" & It.IPAddress(1) & vbCrLf & vbCrLf End If End If Next End If Next MsgBox s End Sub