13 July, 2015

Check if name equals its IP via batch

Hi,

Had a problem that I had a server name and it's IP and needed to make sure that the IP did not change.

Here is a small script to do that, pass the name and IP as parameters and it will give you back errorlevel according to the check (0 for OK).

============================================================
FOR /f "tokens=1,3 delims=: " %%A IN ('ping -n 1 %1') DO IF %%A==Reply set ip=%%B

If %2==%ip% goto ok

exit /B 1

:OK

exit /B 0
============================================================


Enjoy