|
|
|
date: Tue, 3 Jun 2008 22:46:56 -0400,
group: microsoft.public.win32.programmer.wmi
back
Re: How can I obtain the MAC address of a remote machine via a WMI
Script?
Hi,
We've all been through this..
Google 'WMI code creator'
Anyway here's your script (in vbscript)
<code>
strComputer = "domain\name"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_NetworkAdapter instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "MACAddress: " & objItem.MACAddress
Next
</code>
The script needs to have the proper rights on the machine it queries
Running on my machine it lists 12 instances, and 4 different MAC
addresses.
Have fun with that ;)
Rob'
On Jun 4, 4:46 am, "Spin" wrote:
> Gurus,
>
> Running Windows Server 2003 SP2. How can I obtain the MAC address of a
> remote machine via a WMI Script? The script would need to create a WMI
> object and then access the Win32_NetworkAdapter class, which has a property
> that returns the MAC address. I< unfortunately, haven't a clue on how to
> write one.
>
> --
> Spin
date: Wed, 4 Jun 2008 00:37:04 -0700 (PDT)
author: RD
Re: How can I obtain the MAC address of a remote machine via a WMI
Script?
It's a simple WQL request (SQL like for WMI) to list all instances of
Win32_NetworkAdapter class
then, for each of the results, it prints the MACAddress property.
So it's all WMI, works on any remote computer provided you have the
proper user rights (that is admin) on the account that runs the
script.
If you want to logon as another user, google or msdn search for
Management.ManagementScope (I use that in VB.NET)
Hope this helps.
Rob'
On 4 juin, 13:44, "Spin" wrote:
> Does this VB script make a Windows API call to obtain the remote MAC
> address? I can't tell by the code. Forgive my ignorance!
>
> "RD" wrote in message
>
> news:8b819a9d-6434-4ccf-a77f-68e8df2ac686@e39g2000hsf.googlegroups.com...
>
> > Hi,
> > We've all been through this..
> > Google 'WMI code creator'
> > Anyway here's your script (in vbscript)
> > <code>
> > strComputer = "domain\name"
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
> > \CIMV2")
> > Set colItems = objWMIService.ExecQuery( _
> > "SELECT * FROM Win32_NetworkAdapter",,48)
> > For Each objItem in colItems
> > Wscript.Echo "-----------------------------------"
> > Wscript.Echo "Win32_NetworkAdapter instance"
> > Wscript.Echo "-----------------------------------"
> > Wscript.Echo "MACAddress: " & objItem.MACAddress
> > Next
> > </code>
> > The script needs to have the proper rights on the machine it queries
> > Running on my machine it lists 12 instances, and 4 different MAC
> > addresses.
>
> > Have fun with that ;)
date: Wed, 4 Jun 2008 05:49:57 -0700 (PDT)
author: RD
Re: How can I obtain the MAC address of a remote machine via a WMI
Script?
On Jun 4, 5:40 pm, "Spin" wrote:
> "RD" wrote in message
>
> news:76faf4d4-d409-4f98-bc21-a9ef3c8ad05d@a70g2000hsh.googlegroups.com...
>
> >It's a simple WQL request (SQL like for WMI) to list all instances of
> >Win32_NetworkAdapter class
> >then, for each of the results, it prints the MACAddress property.
> >So it's all WMI, works on any remote computer provided you have the
> >proper user rights (that is admin) on the account that runs the
> >script.
> >If you want to logon as another user, google or msdn search for
> >Management.ManagementScope (I use that in VB.NET)
>
> It definitely worked. It picked up the remote MAC address of the machine
> for which I intended it. It also picked up some other MAC addresses as well
> which was kind of weird.
>
> What I did was alter line 1 of the script changing it to:
> strComputer = "DC1"
>
> which resulted in it displaying the MAC of machine DC1 (DC1 has only 1 NIC,
> no other NICs present at all). However the script also displayed a MAC of
> 50:50:54:50:30:30. Kinda weird, huh?
I know. tested it on two computers (both running win xp pro, both with
only one NIC) and on both it reports 10+ instances, with 3 differant
mac addresses.. I don't know what the others are though..
So to be sure, you can change the request to "SELECT * FROM
Win32_NetworkAdapter WHERE DeviceID=1"
If I remember correctly the mac address of the first device listed is
the good one.
Glad it helped.
date: Wed, 4 Jun 2008 12:25:58 -0700 (PDT)
author: RD
Re: How can I obtain the MAC address of a remote machine via a WMI Script?
I see that exact number show up on a hardware
listing script that I use. Maybe there are particular
MAC address constants that represent various
hardware/protocols? I don't know. But in case it's
of use, here's the return of network adapters that was
spit out by an HP PC:
-------------------------------------------------
Description: Intel(R) PRO/100 VE Network Connection
Name: Intel(R) PRO/100 VE Network Connection
Manufacturer:
MAC Address:
Description: RAS Async Adapter
Name: RAS Async Adapter
Manufacturer:
MAC Address:
Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address:
Description: WAN Miniport (L2TP)
Name: WAN Miniport (L2TP)
Manufacturer: Microsoft
MAC Address:
Description: WAN Miniport (PPTP)
Name: WAN Miniport (PPTP)
Manufacturer: Microsoft
MAC Address: 50:50:54:50:30:30
Description: WAN Miniport (PPPOE)
Name: WAN Miniport (PPPOE)
Manufacturer: Microsoft
MAC Address: 33:50:6F:45:30:30
Description: Direct Parallel
Name: Direct Parallel
Manufacturer: Microsoft
MAC Address:
Description: WAN Miniport (IP)
Name: WAN Miniport (IP)
Manufacturer: Microsoft
MAC Address:
Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address: CC:F6:20:52:41:53
Description: Intel(R) PRO/100 VE Network Connection
Name: Intel(R) PRO/100 VE Network Connection
Manufacturer: Intel
MAC Address: 00:E0:18:4F:E3:E0
Description: Packet Scheduler Miniport
Name: Packet Scheduler Miniport
Manufacturer: Microsoft
MAC Address: 00:E0:18:4F:E3:E0
Description: 1394 Net Adapter
Name: 1394 Net Adapter
Manufacturer: Microsoft
MAC Address: 32:9F:90:F8:37:79
----------------------------------------
Your number is in there under WAN Miniport.
I also noticed that a number of items were
returned twice, but only once with a MAC
address. The first item returned was the actual
ethernet card, but its MAC address was only
included with the second instance.
I have no idea of what the explanation is
for that.
> >It's a simple WQL request (SQL like for WMI) to list all instances of
> >Win32_NetworkAdapter class
> >then, for each of the results, it prints the MACAddress property.
> >So it's all WMI, works on any remote computer provided you have the
> >proper user rights (that is admin) on the account that runs the
> >script.
> >If you want to logon as another user, google or msdn search for
> >Management.ManagementScope (I use that in VB.NET)
>
> It definitely worked. It picked up the remote MAC address of the machine
> for which I intended it. It also picked up some other MAC addresses as
well
> which was kind of weird.
>
> What I did was alter line 1 of the script changing it to:
> strComputer = "DC1"
>
> which resulted in it displaying the MAC of machine DC1 (DC1 has only 1
NIC,
> no other NICs present at all). However the script also displayed a MAC of
> 50:50:54:50:30:30. Kinda weird, huh?
>
>
date: Wed, 4 Jun 2008 19:49:02 -0400
author: mayayana
|
|