' =======================================================
‘
'-----------2014.11.10 by Zhang.xh qq:857372828
‘
' =========================================================
Dim STR0,STR1,STR2,STR3
StrComputer = "."
Set objWMIService = GetObject ("winmgmts:\\" & StrComputer & "\root\cimv2")
STR1 = GetIP ()
STR2 = Getmac ()
STR3 = GetHostName ()
MsgBox "IP:" &str1& vbCrLf & "MAC:" &STR2, "Computer name:" &str3
Function GetIP ()
GetIP = ""
Dim ipconfig,ipconfigset
Set Ipconfigset = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration where Ipenabled=true")
For each IPConfig in Ipconfigset
If not IsNull (ipconfig.ipaddress) Then
for i = LBound (ipconfig.ipaddress) to UBound (ipconfig.ipaddress)
' MsgBox ' IP address: "&ipconfig.ipaddress (i),," IP address sent to the network administrator RTX: "
f = f &ipconfig.ipaddress (i) &vbcrlf & "IP:"
Next
End If
' Exit for
Next
GetIP = f
End Function
Function Getmac ()
Getmac = ""
Dim mo,mc
Set MC = GetObject ("winmgmts:"). InstancesOf ("Win32_NetworkAdapterConfiguration")
For each MO in MC
If mo. IPEnabled = True Then
the ' traceprint ' MAC address of the native network card is: "& mo. MacAddress
' MsgBox ' MAC: ' & mo. MacAddress, "Your MAC address is:"
m = M &mo. MacAddress & vbCrLf & "MAC:"
' Exit for
End If
Next
Getmac = m
End Function
Function GetHostName ()
GetHostName = ""
Dim colcomputer,colcomputers
Set Colcomputers = objWMIService.ExecQuery _
("SELECT * from Win32_ComputerSystem")
For each objcomputer in Colcomputers
strComputerName = Objcomputer.name
' MsgBox ' Computer name: ' &strcomputername,, ' Your computer name: '
GetHostName = strComputerName
Exit for
Next
End Function
' ==========================
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/56/CA/wKioL1SOUCvBdCWXAAB2gYTea7M914.jpg "title=" 20141215110235.jpg "alt=" Wkiol1soucvbdcwxaab2gytea7m914.jpg "/>
This article is from the "Technical Achievement Self" blog, please make sure to keep this source http://gotusson.blog.51cto.com/692866/1590024
Using VBS method to obtain the Ip,mac of dual network card or multi-network card, computer name method