1.

Solve : Ping and hostname?

Answer»

Hey all,

Im trying to use hostname of ping address' to manipulate my .txt output
--------------
echo off
set a=1

:start
ping -n 1 -r 4 -a 10.1.1.%a%
echo %errorlevel%
if %errorlevel% ==0 (ping -n 1 -r 4 -a 10.1.1.%a% >> a.txt) else (echo error 10.1.1.%a%)
echo ------------ >> a.txt
echo ------------ >> a.txt
echo ------------ >> a.txt
set /a a+=1
if %a% == 255 goto end
goto start
:end
pause
-----------


so far my output is LIKE the below


Pinging 10.1.1.7 with 32 bytes of DATA:
REPLY from 10.1.1.150: Destination host unreachable.

Ping statistics for 10.1.1.7:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
------------
------------
------------

if there is no IP address assigned it STILL goes into my .txt file because it PINGS myself (10.1.1.150) and gives an unreachable. im trying to get my .txt file to only contain ip address that are reachable and a way i can do it is something like,

if ip = 10.1.1.150 do nothing else >> a.txt

if possible i would prefer hostname as im not using a static IP.  im sorry if my question seems a bit confusing.

Thanks for looking,

Khasiar



Discussion

No Comment Found