Get MAC ID from IP Address

Author Message
FatFingerTony

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 10/10/2006
  • Location: Grand Rapids, MI
  • Status: offline
Get MAC ID from IP Address Friday, October 13, 2006 6:34 AM (permalink)
0
Here's a quick and dirty IP address to MAC ID lookup, gets it from the local ARP table.
 
Note: Don't use it to pull your own (the computer you're running it from) MAC, it gets confused with the local interface address listed in the ARP table.

 On error Resume Next
 Set objShell = CreateObject("WScript.Shell")  'Create Shell Instance
 Msgbox(GetMac("192.168.11.135"))   'Msgbox the results of the GetMac Function, passings an IP Address to it
 Function GetMac(ip)     'Begin GetMac function 
 Set objExec = objShell.Exec("ping -n 4 -w 1000 " & ip) 'Run the PING command in command shell to build ARP table
 WScript.Sleep(2000)     'Sleep 2 seconds, allows ARP table to catch up
 Set objExec = objShell.Exec("arp -a")   'List the ARP table
 strPingResults = LCase(objExec.StdOut.ReadAll)  'Drop the entire ARP table into a variable
 strARPList = Split(strPingResults)   'Break variable into an Array
 n = UBound(strARPList,1)    'Get the size of the Array
 For X = 0 To n      'Loop from 0 to the size of the Array
 If strARPList(x) = ip Then    'Compare the Array single variable to the IP address, if they match...
 For y = 1 To 16     'Loop for 16 (this is used to hunt down the MAC address)
  If strARPList(x+y) <> "" Then   'If the array variable is NOT empty (must be the MAC ID)....
   GetMac = strARPList(x+y) 'Return the MAC ID 
   Exit For   'Exit For Next Loop
  End If
 Next
 End If
 Next
 End Function
 


 
#1
    DiGiTAL.SkReAM

    • Total Posts : 1259
    • Scores: 7
    • Reward points : 0
    • Joined: 9/7/2005
    • Location: Clearwater, FL, USA
    • Status: offline
    RE: Get MAC ID from IP Address Friday, October 13, 2006 7:55 AM (permalink)
    0
    I was unable to get this to work.  On my network, most machines are resolved via WINS... would that affect the output?
    "Would you like to touch my monkey?" - Dieter (Mike Meyers)

    "It is better to die like a tiger, than to live like a pussy."
    -Master Wong, from Balls of Fury
     
    #2
      mcds99

      • Total Posts : 519
      • Scores: 4
      • Reward points : 0
      • Joined: 2/28/2006
      • Status: offline
      RE: Get MAC ID from IP Address Friday, October 13, 2006 8:38 AM (permalink)
      0
      The reason this will not work accross a network segment is you have to be on the network segment you are using ARP on.

      One of the gotch ya's of ARP.

      WMI can do the same, but it does require admin like rights.
      Sam

      Keep it Simple Make it Fun KiSMiF
       
      #3
        DiGiTAL.SkReAM

        • Total Posts : 1259
        • Scores: 7
        • Reward points : 0
        • Joined: 9/7/2005
        • Location: Clearwater, FL, USA
        • Status: offline
        RE: Get MAC ID from IP Address Friday, October 13, 2006 9:02 AM (permalink)
        0
        You are correct on both counts.  I got with our WAN/LAN group, and did a bull session and found that since our switches are VLAN'd out, I can get ARPs for all the machines inside my VLAN, but when crossing into another VLAN, I need to go througha  router, and the ARP broadcasts are stomped on.
        Also, the WMI method of getting MAC addresses is valid, but again, as you said, you need admin rights on the remote machine.
        "Would you like to touch my monkey?" - Dieter (Mike Meyers)

        "It is better to die like a tiger, than to live like a pussy."
        -Master Wong, from Balls of Fury
         
        #4
          FatFingerTony

          • Total Posts : 5
          • Scores: 0
          • Reward points : 0
          • Joined: 10/10/2006
          • Location: Grand Rapids, MI
          • Status: offline
          RE: Get MAC ID from IP Address Monday, October 16, 2006 2:32 PM (permalink)
          0
          Sorry, I should have been more specific about it's function. Yes, ARP tables only hold your local subnets ip addresses, but I needed a free MAC lookup script that would at least pull MACs from foreign IP addresses that show up on local IP range scans.
           
          I have a set of scanner scripts (which I'll post once all my commenting is done) that this mac script is part of, and it pings a range of IPs, if they respond it hit them with three different accounts to gain WMI access, if it fails to grab WMI then it tries to grab a MAC ID to help me investigate what the heck is on our network. I've actually updated this script so that it grabs a vendor name out of a text file by matching the MACs first six digits to give me a little more info to work with. I'd post it, but I can't upload the text reference file (not enough posts to upload) and it needs some trimming, it's currently 1.5 megs and 2/3rds of it can be deleted.
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9