Get IP from MAC address. arp -a not showing device
Asked Answered
I

4

19

I'm trying to write a batch file that's supposed to find the dynamically assigned IP of my Android phone when it's connected to the network (Tenda WiFi router).

So I'm trying arp -a and searching for my phone's MAC address so I can get its IP from the table.

C:\Users\Leeroy>arp -a

Interface: 192.168.0.100 --- 0xb
  Internet Address      Physical Address      Type
  192.168.0.1           c8-3a-35-35-f6-68     dynamic
  192.168.0.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static

The problem is it doesn't show up in the table! I tried ping 192.168.0.255 but it still doesn't show up. I tried requesting 192.168.0.100 (IP of my desktop PC) from the phone's browser, and that sure enough puts the phone on the radar. But I don't have the option to manually do that everytime I want it to appear in the arp table.

How do I get the Android phone to appear in the arp table (without doing anything from it besides connecting to WiFi)?

Inexpiable answered 20/8, 2014 at 12:16 Comment(6)
This might help.Genoa
I'm trying to only rely on Windows commands. Not installing anything. I'd rather just loop through all addresses and ping them, even if it will take entirely too long.Inexpiable
how about thisGenoa
sorry, just seen that you've tried that.Genoa
I would stick a timeout 1 > nul or equivalent before your second for loop to avoid a race condition whereby a ping reply for the device you are after hasn't come back before you call arp -a.Genoa
If you've found a solution, please post it as an answer rather than editing it into the questionRainfall
G
14

I have tried this and it works:

for /L %N in (1,1,254) do start /b ping -n 1 -w 200 192.168.0.%N

provided the phone has ICMP enabled, you should have no problem.

Genoa answered 20/8, 2014 at 13:19 Comment(5)
You could use 'start /b' that will not open new command windowsFreddie
@Freddie Quite right, I had forgotten about that option. Also added some options to ping to make it return quicker.Genoa
I was dreading to go the ping route because I imagined it would take super long, but this is really slick...Inexpiable
Run Wireshark in parallel with a filter expression like eth.src == 12:34:56:78:9a:bc && eth.type == 0x0806 with the known MAC address. This will yield a frame with an Info 192.168.0.123 is at 12:34:56:78:9a:bc upon match. Helpful if the IP address to be found is flushed from a small ARP cache if there are a lot of devices on the network.Barricade
a slightly easier to read version of the command above: for /L %N in (1,1,254) do @start /b ping -n 1 -w 200 192.168.0.%N | findstr -i replyExponible
H
4

M.S.Arun's answer is close to the best. I had this problem for retrieveing some virtual machines IP address for which all I had was the MAC address. A lot of answers like M.S.Aruns's all over stackoverflow and elsewhere, but nobody explains them, nor explains the solution correctly (IMHO).

I tried the technique of pinging all subnet and then do an arp command. The problem was my IP range had 60k+ possible IP address and after scanning all of them (which was not so simple, and really ugly with the start command) the arp table was really poorly populated... Btw it was taking like 30 secs, even while trying with "start ping". I eventually figured out that the arp, being a cache table, flushes itself periodically, which is why this method rarely succeeded.

The solution is to ping all subnet, but after each ping perform an arp command to see if the IP matches your MAC address, which ensures you not to loose information because of the cache nature of the arp tables. To make it proper, I implemented this in Java; the isReachable() method is really cleaner and there are no cmd prompts spawning everywhere on my screen. Moreover, the 60k+ range of IPs scanning takes up to 10sec using Java threads. I think it's a more secure way than batch scripting...

See threadedScan() method here which takes in an array of IPs and looks for the MAC address.

Hope this can help ;)

Haller answered 24/6, 2017 at 13:24 Comment(0)
C
1

If you want find IP from MAC do this

$  arp -n | grep -w -i 'YOUR-MAC' | awk '{print $1}'

Note you must replace YOUR-MAC, with your mac address, keep single quotes

Now, if you want find MAC Address from some IP Try this:

$  arp -n | grep -w -i 'YOUR-IP' | awk '{print $3}'

Enjoy!

Cohesive answered 5/2, 2015 at 10:58 Comment(0)
B
1

This Batch Code will fetch the below,

  1. PC Name
  2. IP Address
  3. MAC Address
  4. Computer Description(If Available)

Please save the below code in anyname.bat format and run it. It will output the results in a separate text file.

    :: This Windows Batch(CMD) File fetches All the Details of the Nearby PC's of Same VLAN (Upto 254 host's).
    :: Windows OS (CMD)
    :: Author : [M.S.Arun][1]

    :: #****************************************************************** Start of Script ********************************************************************#

    @echo off
    title Remote PC Details Fetching Script(PC Name / IP's / Computer Description)
    echo. > %cd%\PC_Details_Temp.txt
    echo Remote PC Details Fetching Script (PC Name / IP's / Computer Description) details of the Nearby PC's of Same VLAN.(Upto 254 Hosts)
    echo.
    set /p input_ip="Please Enter the IP Range(Eg:192.168.1) :  " && echo
    set /p input_ip_start="Please Enter Start IP Range(Eg:1) :  " && echo
    set /p input_ip_end="Please Enter End IP Range(Eg:254) :  " && echo
    echo. >> %cd%\PC_Details_Temp.txt
    @echo on
    for /l %%i in (%input_ip_start%, 1, %input_ip_end%) do nbtstat -a %input_ip%.%%i | findstr /c:"MAC" /c:"<00>" | findstr /c:"MAC" /c:"UNIQUE" >> %cd%\PC_Details_Temp.txt && echo     IP Address  = %input_ip%.%%i >> %cd%\PC_Details_Temp.txt
    @echo off
    echo. > %cd%\PC_Details_Logs.txt
    echo. > %cd%\PC_Details_Logs.txt
    echo This Batch Script fetches All the Details of the Nearby PC's of Same VLAN.(Starting from 1 to 254 host's) >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC Host Name: >> %cd%\PC_Details_Logs.txt
    find "UNIQUE" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC IP Address: >> %cd%\PC_Details_Logs.txt
    find "IP" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC MAC Address: >> %cd%\PC_Details_Logs.txt
    find "MAC" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC Seat No's. and Vnet No's: >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    net view /all >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    arp -a >> %cd%\PC_Details_Logs.txt
    :: del %cd%\PC_Details_Temp.txt
    echo.
    echo Completed Successfully..!
    echo.
    pause

    :: #****************************************************************** End of Script ********************************************************************#

Screenshots For References, enter image description here

enter image description here

Brinkmanship answered 19/3, 2017 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.