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
Showing posts with label ping. Show all posts
Showing posts with label ping. Show all posts
13 July, 2015
15 February, 2013
Get machine IP via script (and check if it's up)
Hi,
I encountered a problem, I have a list of servers from AD and wanted to get the IP on each server.
It seems that this is not easy, I could not find a clean way to do it on the web.
As a batch fan I wrote a small script that get's, as an input, a list of names, ping them and echo out to a file the name and the IP (so you can import it to excel easily).
You need to prepare a file named list.txt with all the names to convert to IP.
Next, create 2 files:
STEP1.CMD
========================================
del pinged_list.txt /q
for /f %%A in (list.txt) do (step2.cmd %%A)
========================================
STEP2.CMD
========================================
ping %1 -n 1 -w 1| find "TTL=" > 1.txt
if %errorlevel% NEQ 0 goto end
for /f "tokens=1-3 delims= " %%A in (1.txt) do (echo %%C > 2.txt)
for /f "tokens=1-3 delims=:" %%A in (2.txt) do (echo %1, %%A >>pinged_list.txt)
del 2.txt /q
:end
del 1.txt /q
=========================================
run step1.cmd and wait to the pinged_list.txt file to be prepared.
Enjoy...
I encountered a problem, I have a list of servers from AD and wanted to get the IP on each server.
It seems that this is not easy, I could not find a clean way to do it on the web.
As a batch fan I wrote a small script that get's, as an input, a list of names, ping them and echo out to a file the name and the IP (so you can import it to excel easily).
You need to prepare a file named list.txt with all the names to convert to IP.
Next, create 2 files:
STEP1.CMD
========================================
del pinged_list.txt /q
for /f %%A in (list.txt) do (step2.cmd %%A)
========================================
STEP2.CMD
========================================
ping %1 -n 1 -w 1| find "TTL=" > 1.txt
if %errorlevel% NEQ 0 goto end
for /f "tokens=1-3 delims= " %%A in (1.txt) do (echo %%C > 2.txt)
for /f "tokens=1-3 delims=:" %%A in (2.txt) do (echo %1, %%A >>pinged_list.txt)
del 2.txt /q
:end
del 1.txt /q
=========================================
run step1.cmd and wait to the pinged_list.txt file to be prepared.
Enjoy...
19 May, 2009
Smart Ping when restarting
Hi,
You restart a remote server because you installed some new MS updates and you need to know when it's back online.
What we all do?, start pinging the server and continue to do other things.
when we come back after few minutes to the ping window we see that the server is online but we missed to see it's gone offline.
The following script (I called it "Smart Ping") will check the output from the ping action and look for specific word to let you know that the server went down and went up again.
Fill free to change the words it searches as you see fit in your environment.
=======================================
echo off
cls
:dead
title Server [%1] is going to shut down [%time%]...
ping -n 1 -w 300 %1 find "Request timed out."
IF %ERRORLEVEL% == 0 (goto back_alive) ELSE (goto dead)
:back_alive
title Server [%1] is down [%time%]...
ping -n 1 -w 300 %1 find "TTL"
IF %ERRORLEVEL% == 0 (goto end) ELSE (goto back_alive)
:end
title Server [%1] is Back online [%time%]...
pause
=======================================
Enjoy...
You restart a remote server because you installed some new MS updates and you need to know when it's back online.
What we all do?, start pinging the server and continue to do other things.
when we come back after few minutes to the ping window we see that the server is online but we missed to see it's gone offline.
The following script (I called it "Smart Ping") will check the output from the ping action and look for specific word to let you know that the server went down and went up again.
Fill free to change the words it searches as you see fit in your environment.
=======================================
echo off
cls
:dead
title Server [%1] is going to shut down [%time%]...
ping -n 1 -w 300 %1 find "Request timed out."
IF %ERRORLEVEL% == 0 (goto back_alive) ELSE (goto dead)
:back_alive
title Server [%1] is down [%time%]...
ping -n 1 -w 300 %1 find "TTL"
IF %ERRORLEVEL% == 0 (goto end) ELSE (goto back_alive)
:end
title Server [%1] is Back online [%time%]...
pause
=======================================
Enjoy...
01 April, 2009
See which machine is alive...
If you need to run on a list of machines with some command, you want to make sure that the workstations (or servers) are alive and pingble.
The following script allow you to do just that.
It contains 3 elements:
By for now...
The following script allow you to do just that.
It contains 3 elements:
- "computers.txt" - the full list of computers in your LAN (probably from AD), names only!!!
- "Step1.cmd" - run's the next file in a loop on each line from "computers.txt"
- "Step2.cmd" - The command itself.
content of step1.cmd:
======================
for /f %%A in (computers.txt) do (step2.cmd %%A)
======================
content of step2.cmd:
======================
ping -n 1 -w 300 %1 find "TTL">nul
IF %ERRORLEVEL% == 0 (echo %1 >> alive.txt) ELSE (echo %1 >> dead.txt)
======================
By for now...
Subscribe to:
Posts (Atom)