'代码出处:http://zhidao.baidu.com/question/155475470.html
Private Sub Form_Load()
Dim Mac
strComputer = "."
Mac = ""
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & strComputer & "/root/cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objItem In colItems
Mac = Mac + " " + objItem.macaddress
Next
strComputer = "."
Set objWMI = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each Ip In colIP
If Not IsNull(Ip.ipaddress) Then
For I = LBound(Ip.ipaddress) To UBound(Ip.ipaddress)
Text1.Text = Ip.ipaddress(I) '取内网IP地址
Text2.Text = Ip.Description(I) '取网卡类型
Text3.Text = Ip.macaddress(I) '取MAC地址
Next
End If
Next
End Sub