Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - PC Name and MAC Addresses

Reply
 
Old 09-25-2008   #1 (permalink)
NoSurprises


 
 

PC Name and MAC Addresses

Hi,

Bit of a specific script required here, hopefully someone can assist )

Looking for a script that can find out the MAC addresses of PC's and input
them into a text file. Formating needs to be similar to:-

IP Address <space or Tab> PC Name <space or TAB> MAC Address

IP Address isn't overly important, but helpful. Not sure where the best
place to pull the information from is, perhaps DHCP?

The script is to be run on a weekly/monthly basis to make sure list is kept
up to date, and needs to be fully automated.

Many Thanks in advance to anyone who responds )

Any ideas?



My System SpecsSystem Spec
Old 09-25-2008   #2 (permalink)
Anuj


 
 

RE: PC Name and MAC Addresses

you may pull the data using Nbtstat command in your script.

"NoSurprises" wrote:
Quote:

> Hi,
>
> Bit of a specific script required here, hopefully someone can assist )
>
> Looking for a script that can find out the MAC addresses of PC's and input
> them into a text file. Formating needs to be similar to:-
>
> IP Address <space or Tab> PC Name <space or TAB> MAC Address
>
> IP Address isn't overly important, but helpful. Not sure where the best
> place to pull the information from is, perhaps DHCP?
>
> The script is to be run on a weekly/monthly basis to make sure list is kept
> up to date, and needs to be fully automated.
>
> Many Thanks in advance to anyone who responds )
>
> Any ideas?
>
>
My System SpecsSystem Spec
Old 09-25-2008   #3 (permalink)
NoSurprises


 
 

RE: PC Name and MAC Addresses

Hi Anuj,

Thanks for responding. My skills in vbscipt in Nil, so I really need this
doing for me unfortuntley )

Anyone who makes this script for me, will recieve a lollipop and gold star )


"Anuj" wrote:
Quote:

> you may pull the data using Nbtstat command in your script.
>
> "NoSurprises" wrote:
>
Quote:

> > Hi,
> >
> > Bit of a specific script required here, hopefully someone can assist )
> >
> > Looking for a script that can find out the MAC addresses of PC's and input
> > them into a text file. Formating needs to be similar to:-
> >
> > IP Address <space or Tab> PC Name <space or TAB> MAC Address
> >
> > IP Address isn't overly important, but helpful. Not sure where the best
> > place to pull the information from is, perhaps DHCP?
> >
> > The script is to be run on a weekly/monthly basis to make sure list is kept
> > up to date, and needs to be fully automated.
> >
> > Many Thanks in advance to anyone who responds )
> >
> > Any ideas?
> >
> >
My System SpecsSystem Spec
Old 09-25-2008   #4 (permalink)
James Whitlow


 
 

Re: PC Name and MAC Addresses

"NoSurprises" <NoSurprises@xxxxxx> wrote in message
news:68D656F8-B0DB-4C1D-A4F6-E9DA01C576F6@xxxxxx
Quote:

> Hi Anuj,
>
> Thanks for responding. My skills in vbscipt in Nil, so I really need this
> doing for me unfortuntley )
>
> Anyone who makes this script for me, will recieve a lollipop and gold star
> )
The below is quickly written and not well tested, but it might meet your
needs. Richard Mueller might come along later and offer you something more
flexible & reliable.

You will need to create a file in the same directory as the script
called 'comps.txt' with a list of computer, 1 per line. The script will
output to a new file called 'MAC.txt'. It is tab delimited and should open
fine in Excel. The script uses WMI, so you will need to run it using an
account with administrative privileges on the computers to be scanned. Also,
some firewalls block WMI and might prevent the script from working.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Option Explicit

Dim oFSO, aComps, sComp, oFile, oWMI, oPing, oIP
Dim sIP, sNetBIOS, sMAC

Set oFSO = CreateObject("SCripting.FileSystemObject")
With oFSO.OpenTextFile("Comps.txt", 1)
aComps = Split(.Readall, vbNewLine)
End With

Set oFile = oFSO.OpenTextFile("MACs.txt", 2, True)
oFile.WriteLine "IP Address" & vbTab & "NetBIOS Name" _
& vbTab & "MAC Address"

For Each sComp in aComps
On Error Resume Next
Set oWMI = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
On Error Goto 0
If VarType(oWMI) = 9 Then
For Each oPing in oWMI.InstancesOf _
("Win32_PingStatus WHERE Address = '" & sComp & _
"' AND ResolveAddressNames=True")
sIP = oPing.ProtocolAddress
sNetBIOS = oPing.ProtocolAddressResolved
If InStr(sNetBIOS, ".") > 0 Then
sNetBIOS = Left(sNetBIOS, InStr(sNetBIOS, ".") -1)
End If
Next
For Each oIP in oWMI.InstancesOf _
("Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
If oIP.IPAddress(0) = sIP Then
sMAC = oIP.MACAddress
Exit For
End If
Next
oFile.WriteLine sIP & vbTab & sNetBIOS & vbTab & sMAC
End If
Set oWMI = Nothing
Next

MsgBox "Done"
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


My System SpecsSystem Spec
Old 09-25-2008   #5 (permalink)
OldDog


 
 

Re: PC Name and MAC Addresses

Or this (same idea, same rules apply, list of computers is called C:
\Scripts\servers.txt;

Const ForReading = 1
Const ForWriting = 2
Dim strComputer
Dim objWMIService
Dim propValue
Dim SWBemlocator
Dim UserName
Dim Password

UserName = ""
Password = ""

'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Scripts\servers.txt",
ForReading)
Set oFile = objFSO.OpenTextFile("MACs.txt", 2, True)
oFile.WriteLine "IP Address" & vbTab & "Computer Name" _
& vbTab & "MAC Address"

Do Until objTextFile.AtEndOfStream
strComputer = Trim(objTextFile.Readline)
If (strComputer <> "") Then
GetInfo
End If
Loop

Sub GetInfo
Dim obj_Adapter, obj_Adapters
Dim obj_IP, obj_IPs, str_IPs
Set objWMILocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objWMILocator.ConnectServer(strComputer,"\root
\CIMV2",UserName,Password)
Set colItems = objWMIService.ExecQuery("SELECT * FROM
Win32_NetworkAdapterConfiguration where IPEnabled = True", "WQL", _
wbemFlagReturnImmediately +
wbemFlagForwardOnly)
for each obj_Adapter In colItems
obj_IPs = obj_Adapter.IPAddress
For Each obj_IP In obj_IPs
str_IPs = str_IPs & obj_IP & ";"
Next
WScript.Echo "Computer Name: " & strComputer & vbTab & "IP: "
& str_IPs & vbTab & "MACAddress: " & obj_Adapter.MACAddress
oFile.WriteLine str_IPs & vbTab & strComputer & vbTab &
obj_Adapter.MACAddress

Next
End Sub
My System SpecsSystem Spec
Old 09-25-2008   #6 (permalink)
NoSurprises


 
 

Re: PC Name and MAC Addresses

James/Olddog,

Many thanks to you both for coming back to me on this.

James:- Looking at this script it sugests that the scripts pings the PC,
and gets the details from that? If this is the case, the solution isn't fit
for my purpose, as this will only contact PCs that are switched on at the
time. I need the details to be kept up to date, and the only place where PCs
are up to date is within active directory - not sure if you can pull the info
from AD?

I also get an error on the script - Line 20 Char1, object required.

OldDog:- I got a number of errors with your script, and tried to rectify,
but suspect I have made things worse! However your script looks as if it
does not do anything with Pings - does your script also rely on the PC being
switched on at the time?

Many Thanks to you both for taking the time out to sort this out for me!

"James Whitlow" wrote:
Quote:

> "NoSurprises" <NoSurprises@xxxxxx> wrote in message
> news:68D656F8-B0DB-4C1D-A4F6-E9DA01C576F6@xxxxxx
Quote:

> > Hi Anuj,
> >
> > Thanks for responding. My skills in vbscipt in Nil, so I really need this
> > doing for me unfortuntley )
> >
> > Anyone who makes this script for me, will recieve a lollipop and gold star
> > )
>
> The below is quickly written and not well tested, but it might meet your
> needs. Richard Mueller might come along later and offer you something more
> flexible & reliable.
>
> You will need to create a file in the same directory as the script
> called 'comps.txt' with a list of computer, 1 per line. The script will
> output to a new file called 'MAC.txt'. It is tab delimited and should open
> fine in Excel. The script uses WMI, so you will need to run it using an
> account with administrative privileges on the computers to be scanned. Also,
> some firewalls block WMI and might prevent the script from working.
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Option Explicit
>
> Dim oFSO, aComps, sComp, oFile, oWMI, oPing, oIP
> Dim sIP, sNetBIOS, sMAC
>
> Set oFSO = CreateObject("SCripting.FileSystemObject")
> With oFSO.OpenTextFile("Comps.txt", 1)
> aComps = Split(.Readall, vbNewLine)
> End With
>
> Set oFile = oFSO.OpenTextFile("MACs.txt", 2, True)
> oFile.WriteLine "IP Address" & vbTab & "NetBIOS Name" _
> & vbTab & "MAC Address"
>
> For Each sComp in aComps
> On Error Resume Next
> Set oWMI = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
> On Error Goto 0
> If VarType(oWMI) = 9 Then
> For Each oPing in oWMI.InstancesOf _
> ("Win32_PingStatus WHERE Address = '" & sComp & _
> "' AND ResolveAddressNames=True")
> sIP = oPing.ProtocolAddress
> sNetBIOS = oPing.ProtocolAddressResolved
> If InStr(sNetBIOS, ".") > 0 Then
> sNetBIOS = Left(sNetBIOS, InStr(sNetBIOS, ".") -1)
> End If
> Next
> For Each oIP in oWMI.InstancesOf _
> ("Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
> If oIP.IPAddress(0) = sIP Then
> sMAC = oIP.MACAddress
> Exit For
> End If
> Next
> oFile.WriteLine sIP & vbTab & sNetBIOS & vbTab & sMAC
> End If
> Set oWMI = Nothing
> Next
>
> MsgBox "Done"
> '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
>
My System SpecsSystem Spec
Old 09-25-2008   #7 (permalink)
OldDog


 
 

Re: PC Name and MAC Addresses

I got a number of errors with your script, and tried to rectify,
but suspect I have made things worse! However your script looks as if
it
does not do anything with Pings - does your script also rely on the PC
being
switched on at the time?

You need to wath out for the wrap. When a script is posted some of the
lines get wraped around in unfortunate places.

For example Set objWMIService =
objWMILocator.ConnectServer(strComputer,"\root
\CIMV2",UserName,Password)
should be all one line


And yes, it relies on the PC being switched on.
I do not believe that this information is kept in AD, although I may
be wrong on that.

OldDog
My System SpecsSystem Spec
Old 09-25-2008   #8 (permalink)
James Whitlow


 
 

Re: PC Name and MAC Addresses

"NoSurprises" <NoSurprises@xxxxxx> wrote in message
news9941F71-3948-45F6-AD4C-20D50836A8A6@xxxxxx
Quote:

> James/Olddog,
>
> Many thanks to you both for coming back to me on this.
>
> James:- Looking at this script it sugests that the scripts pings the PC,
> and gets the details from that? If this is the case, the solution isn't
> fit
> for my purpose, as this will only contact PCs that are switched on at the
> time. I need the details to be kept up to date, and the only place where
> PCs
> are up to date is within active directory - not sure if you can pull the
> info
> from AD?
>
> I also get an error on the script - Line 20 Char1, object required.
>
> OldDog:- I got a number of errors with your script, and tried to rectify,
> but suspect I have made things worse! However your script looks as if it
> does not do anything with Pings - does your script also rely on the PC
> being
> switched on at the time?
The code I posted as well as that posted by OldDog will require the
computer to be on. Both are connecting to the computer's WMI interface.

On line 20, I see 'If VarType(oWMI) = 9 Then'. Is this what you have on
line 20 of your script? If not, please advise.

As far as I know, Active Directory does not store the MAC address(es) of
the computer. One thing you might want to consider is adding code to your
logon script rather than scanning for the information. You can add an
attribute to AD or, perhaps use one that is not in use ('carLicense' maybe)
and then write the MAC address there.


My System SpecsSystem Spec
Old 09-25-2008   #9 (permalink)
Al Dunbar


 
 

Re: PC Name and MAC Addresses


"James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message
news:OsvhEyzHJHA.468@xxxxxx
Quote:

> "NoSurprises" <NoSurprises@xxxxxx> wrote in message
> news9941F71-3948-45F6-AD4C-20D50836A8A6@xxxxxx
Quote:

>> James/Olddog,
>>
>> Many thanks to you both for coming back to me on this.
>>
>> James:- Looking at this script it sugests that the scripts pings the PC,
>> and gets the details from that? If this is the case, the solution isn't
>> fit
>> for my purpose, as this will only contact PCs that are switched on at the
>> time. I need the details to be kept up to date, and the only place where
>> PCs
>> are up to date is within active directory - not sure if you can pull the
>> info
>> from AD?
>>
>> I also get an error on the script - Line 20 Char1, object required.
>>
>> OldDog:- I got a number of errors with your script, and tried to rectify,
>> but suspect I have made things worse! However your script looks as if it
>> does not do anything with Pings - does your script also rely on the PC
>> being
>> switched on at the time?
>
> The code I posted as well as that posted by OldDog will require the
> computer to be on. Both are connecting to the computer's WMI interface.
>
> On line 20, I see 'If VarType(oWMI) = 9 Then'. Is this what you have on
> line 20 of your script? If not, please advise.
>
> As far as I know, Active Directory does not store the MAC address(es)
> of the computer. One thing you might want to consider is adding code to
> your logon script rather than scanning for the information. You can add an
> attribute to AD or, perhaps use one that is not in use ('carLicense'
> maybe) and then write the MAC address there.
I'll go out on a limb here and state that AD does not keep track of the MAC
address. Nor the IP address. the MAC address, in fact, is not a property of
the computer, per se, but of the network adapter. And the network adapter
can be replaced with another one...

Any method that collects mac address information will require that the
computer be powered on when the information is collected. James' suggestion
of collecting this in the logon script probably makes the most sense.

Other possible alternatives:

- SMS might track this information. An expensive addon if that is the only
reason you'd buy it, but if you already have it...

- If you have wake-on-lan capable computers, you might be able to force them
awake long enough to collect the information using WMI. Either that, or
perhaps the NIC could be queried directly for such info without actually
powering on the whole system.

/Al


My System SpecsSystem Spec
Old 09-25-2008   #10 (permalink)
James Whitlow


 
 

Re: PC Name and MAC Addresses

"Al Dunbar" <AlanDrub@xxxxxx> wrote in message
news:eiw%23qn2HJHA.4240@xxxxxx
Quote:

> - SMS might track this information. An expensive addon if that is the only
> reason you'd buy it, but if you already have it...
Indeed it does, at least with the way it is configured at my company. I
wrote a small script sometime back that gets a list of computers for a
certain site and uses SMS to get the MAC addresses and then fires WoL
packets at them. I use it to wake all of the computers at a particular site
when needed (it saves me a lot of walking and a sore fingertip :-).


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Addresses Live Mail
addresses Vista mail
Bad Addresses for TO: Vista mail
IP addresses Vista networking & sharing
addresses Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46