2

I created a batch file that checks if an ip address is online (on the same network). I use the ping command. The program works great, but unfortunately, they ip addresses of the devices change to much, so I have to re-look up the IP address, and restart the program. I am looking for an easy replacement for the IP address, as this is no longer working. i would also need to know the method of detecting whether or not it is online, assuming I can't keep using ping with errorlevel, or tracert with errorlevel. I just need to make sure that the address doesn't change.

Edit: I think I will use the mac address, as that doesn't change, only, I need a way to detect if the mac address is online, but not using the arp -a command, as that displays a list of the mac address, but doesn't allow you to single one out. I hope this makes some since.

2 Answers2

3

In Windows you can run 'arp -a' to see all the devices connected to your computer.

This command will list each device's MAC and IP address, so you can use this output to find the updated IP address of your device on this list.

Within your .bat script, you can parse out the variables

Reference: ARP: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/arp.mspx?mfr=true

Parsing text in .bat script: Parsing string in batch file

Community
  • 1
  • 1
Andy
  • 93
  • 1
  • 7
0

A good idea for substituting the IP is to lookup for the mac address using the IP once known and store that for further pings. If the ip is not there because of re-assignment, lookup using the MAC which is not going to change.

In linux,

#Get the from local arp table
ipaddr=$(arp | grep 52:45:32:3E:B3:C9 | awk ' { print $1 } ')

This code can be sand witched to your existing code that checks the availability periodically. Refer: How to ping MAC adrress in linux

Community
  • 1
  • 1
Karthik S
  • 91
  • 1
  • 10
  • 1
    I think the questioner wants the soloution in batch script. – Monacraft Nov 19 '13 at 03:14
  • Awesome, but I need this for batch. Whenever I try to "ping" the Mac Address, i get nothing but error. –  Nov 19 '13 at 03:15
  • 1
    @coltonon Use in windows as : arp -a | findstr 192.168.0.2 , this will return the string whose second parameter is the mac address. Eg output for "arp -a | findstr 192.168.0.2" is as follows 192.168.0.2 01-00-5e-00-00-16 static --> here "01-00-5e-00-00-16" is the mac address. if the ping with ip fails relookup the arp with the stored mac address like arp -a | findstr 01-00-5e-00-00-16 – Karthik S Nov 19 '13 at 03:26