Get IP Address and MAC Address via script
- From: "Sean Murphy" <sean@xxxxxxxxxx>
- Date: 27 Mar 2007 11:16:57 -0700
Hi all,
I realize this topic has been discussed before, but unfortunately I am
unable to find the answer I'm looking for in previous threads.
I am currently writing a domain migration script to join workstations
to an Active Directory domain. As part of the script, I am gathering
computer information and writing success/failure information to a
database. Two of the columns in the database are for IP Address and
MAC Address. The following script seems to give me most of what I'm
looking for. Obviously, I'm not going to echo these values to the
screen, rather store them and write them to the database. However,
I've realized that while the script will ignore all adapters where the
IP Address is 0.0.0.0, it does not account for multiple adapters with
a valid IP Address. In other words, the last one in the loop with a
valid IP will be stored in the variable.
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled
= True")
For Each oAdapter in colAdapters
For Each sIPAddress in oAdapter.IPAddress
If sIPAddress <> "0.0.0.0" Then
Wscript.Echo "IP Address:" & sIPAddress & vbcrlf & "MAC
Address:" & oAdapter.MACAddress
End If
Next
Next
Has any one got an idea how to handle the case where there may be
multiple adapters with an IP Address or a single adapter with multiple
IP Addresses?
Thanks in advance for your consideration.
Regards,
Sean Murphy
Ensynch, Inc.
Whatever IT Takes
.
- Follow-Ups:
- Re: Get IP Address and MAC Address via script
- From: OldDog
- Re: Get IP Address and MAC Address via script
- Prev by Date: Re: vb script to call values from a text file and start service
- Next by Date: Re: Get IP Address and MAC Address via script
- Previous by thread: Excel Copy, Past into another work***
- Next by thread: Re: Get IP Address and MAC Address via script
- Index(es):