Search code examples
batch-filecmdinternet-explorer-11pingnetwork-connection

Detect connection lost with network device and stop application


I would like to create a batch app which is pinging constantly my network device. Once Result changes into not found it should stop a certain application or my internet explorer.

How do I start with this?

I know i can ping my device with ping 192.168.0.1 -t constantly but how to stop the application with the result ?

Thanks in advance,

Regards, J


Solution

  • I have answered this one previously with a nice little batch file.

    The modification you need to make the above answer work would be:

    :a
    ping -n 1 www.google.com | findstr TTL && goto a
    taskkill /IM <Your Task Name>
    

    This will loop until the connection fails, then end script. You can add another goto a and make it loop again

    • ping checks the connection between you and the location provided
    • -n 1 number of times to check (1)
    • | pipes the result to the next command
    • findstr TTL Find String, finds a string (TTL - Time to live) in the output

    Live ping: Reply from xxx.xxx.xxx.xxx: bytes=32 time=25ms TTL=54

    Dead ping: Reply from xxx.xxx.xxx.xxx: Destination host unreachable.

    • && Continue with command if previous command completed. Same as doing IF NOT ERRORLEVEL 1
    • goto a a simple jump to a label (:a) in the script