Windows scripting

Posted on

QUESTION :

I want to know if someone is online on the same network using ICMP requests.

Being able to ping another workstation on the network to see if its currently on.

A batch file with if and then statements, if 100% packet loss then says user is unavailable.
if ping was successful then user is available.

I’m not sure how to go about with this batch file.

ANSWER :

Like this:

setlocal EnableDelayedExpansion

set IP=...
for /f "delims=() tokens=2" %%a in ('ping %IP% ^| find "% loss"') do (
  set loss=%%a
  set loss=!loss:% loss=!
  if !loss! equ 100 (
    echo %IP% is unavailable
  ) else (
    echo %IP% is available
  )
)

endlocal

Leave a Reply

Your email address will not be published.