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)?
To see all of the devices connected to your network, type arp -a in a Command Prompt window. This will show you the allocated IP addresses and the MAC addresses of all connected devices.
Can you find an IP address from a MAC address? Yes. Open a Command Prompt window and enter the command arp -a. The output shows all of the IP addresses that are active on your network.
If arp broadcast enable is not displayed in the command output, ARP broadcast is not enabled. Run the arp broadcast enable command to enable ARP broadcast on the sub-interface. Check the number of ARP entries on the device.
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.
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With