Results 1 to 4 of 4

Thread: script to get MAC address info. from DHCP

  1. #1
    SalemOR97301 Guest

    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?

  2. #2
    Shay Levy [MVP] Guest

    Re: script to get MAC address info. from DHCP

    Try with netsh:

    C:\> netsh -c dhcp server scope 192.168.1.0 show clients

  3. #3
    Join Date
    Dec 2007
    Posts
    2,291

    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

  4. #4
    Join Date
    May 2009
    Posts
    539

    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.

Similar Threads

  1. Replies: 3
    Last Post: 30-01-2012, 11:07 PM
  2. DHCP address
    By mangotra_rohit123 in forum Networking & Security
    Replies: 1
    Last Post: 20-04-2011, 05:56 PM
  3. Can't get IP address via DHCP
    By intoxicating in forum Networking & Security
    Replies: 3
    Last Post: 02-02-2011, 07:29 PM
  4. DHCP deny mac address
    By HWhite in forum Windows Server Help
    Replies: 5
    Last Post: 28-03-2009, 12:26 AM
  5. Replies: 0
    Last Post: 04-11-2008, 01:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,645,437.51107 seconds with 17 queries