script to get MAC address info. from DHCP
I have an application that I need to import all the MAC addresses for all
hostnames into. I haven't found a way other than to an nbtstat -a
COMPUTERNAME. Of course the only issue with that one is the machines have to
be powered on to get a result. Is there any way to extract the MAC address
from DHCP?
Re: script to get MAC address info. from DHCP
Try with netsh:
C:\> netsh -c dhcp server scope 192.168.1.0 show clients
Re: script to get MAC address info. from DHCP
Check the below code and save it in the .vbs file format to get Mac Address information:
Code:
Option Explicit
Const ADS_PROPERTY_UPDATE = 2
Const COMPUTERLOCATION = "ou=Member Servers,dc=yourdomain,dc=com"
Const ATTRIBUTETOUSE = "otherTelephone"
Dim wshNetwork, strComputerName
Set wshNetwork = WScript.CreateObject("WScript.Network")
strComputerName = wshNetwork.ComputerName
Dim objWMIService, colNetCards, objComputer, objNetCard
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
Set objComputer = GetObject("LDAP://cn=" & strComputerName & "," & COMPUTERLOCATION)
For Each objNetCard in colNetCards
objComputer.PutEx ADS_PROPERTY_APPEND, ATTRIBUTETOUSE, Array(objNetCard.MACAddress)
objComputer.SetInfo
Next
Re: script to get MAC address info. from DHCP
I dont think that you will be able to get the Mac Address information via DHCP. Normally DHCP artibutes IP from MAC and it is not the other way around. IP to Mac coversion is done by ARP and its the computer itself that answers ARP requests so if it is off then it will obviously not going to answer. I will recommend you to store the Mac in your AD directly since AD supports custom attributes.