求助 VB6如何获取网卡名称及DNS地址
在网上找了些代码,可以实现获取IP地址,掩码、网关,网卡描述,Mac地址等信息,如何获取网卡名称(本地连接、以太网等),不是网卡描述。还有DNS服务器地址!
2021-02-08 12:20
程序代码: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

2021-02-08 12:39


2021-02-08 13:35



2021-02-08 13:38
程序代码:Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Dim buffer As String Shell "cmd /c nslookup>>1.txt ", vbHide Sleep 1000 Open "1.txt" For Input As #1 Line Input #1, buffer Close #1 MsgBox buffer End Sub
程序代码:Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Form_Load() Dim data As String Dim buffer As String Shell "cmd /c nslookup>>1.txt ", vbHide Sleep 1000 Open "1.txt" For Input As #1 Line Input #1, data Line Input #1, buffer Close #1 MsgBox data & vbCrLf & buffer End Sub
[此贴子已经被作者于2021-2-8 13:55编辑过]

2021-02-08 13:52
2021-08-27 17:13
2021-08-31 13:44