Using VBS method to obtain the Ip,mac of dual network card or multi-network card, computer name method

Source: Internet
Author: User

' =======================================================

'-----------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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.