What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Can I create an inverse Ping sensor?

Votes:

0

In our network, we monitor devices that usually should not be reachable. If they go online, something is wrong. A typical example for this would be a scenario of a backup ISDN router going online only if the usual broadband Internet connection fails.

I want to set up a Ping sensor that acts in an inverse or reverse way: It shows a green OK status if a device is not reachable, and a red Down status when a device answers to a Ping.

How can I do that?

custom-script-exe custom-sensor exe exe-sensor inverse ping prtg reverse

Created on Oct 13, 2010 12:40:21 PM by  Daniel Zobel [Product Manager]

Last change on Jan 4, 2023 9:12:14 AM by  Brandy Greger [Paessler Support]



3 Replies

Accepted Answer

Votes:

1

This article applies as of PRTG 22

Inverse ping with a Windows script file

With an EXE/Script sensor, you can use a Windows command script (.cmd or .bat) to send a ping request to a device and return an error when it is actually reachable.

We have successfully tested the following script:

@echo off
PING %1 > nul
if errorlevel 1 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)

For Windows 2008 and Windows 7, use this script (see answer below):

@echo off

ping -n 2 %1|Findstr /I /C:"timed out" /C:"host unreachable" /C:"could not find host" > nul
if %errorlevel%==0 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)

Steps to take

  1. In the \Custom Sensors\EXE subfolder of the PRTG program directory, create a .bat or .cmd file inverse_ping.cmd that contains the script shown above. In a cluster installation, copy this file to every cluster node.
  2. In PRTG, add a new EXE/Script sensor.
    • In the sensor settings, choose inverse_ping.cmd from the EXE/Script dropdown list.
    • In the Parameters field, enter the DNS name or IP address of the device you want to ping.
    • Save your settings.
  3. The sensor starts monitoring immediately.
    • If the configured device does not answer to a ping, the sensor shows a green OK status, the last message OK - Ping to xyz failed, and the last result 0.
    • If the configured device does actually answer to a ping, the sensor shows a red Down status, the last message Error - Ping to xzy successful, and the last result 1.

Notes

  • The values returned by the script do not correspond to the measured ping times, but merely indicate the status. To additionally measure ping times, you can add another sensor. See How to create/customize statistical Ping sensor? for more information.
  • As usual, you can set up notification triggers to be notified when the EXE/Script sensor's status changes.
  • Issues related to custom sensors are not covered by the 24-hour support offer from Paessler.

Created on Oct 13, 2010 1:04:06 PM by  Daniel Zobel [Product Manager]

Last change on Dec 29, 2022 3:11:16 PM by  Brandy Greger [Paessler Support]



Votes:

1

This doesn't work on Windows 2008 R2

Looks like this issue - http://superuser.com/questions/403905/ping-from-windows-7-get-no-reply-but-sets-errorlevel-to-0

I used this instead as per the URL above

@echo off

ping -n 2 %1|Findstr /I /C:"timed out" /C:"host unreachable" > nul
if %errorlevel%==0 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)

Created on Jan 14, 2013 1:49:09 AM

Last change on Jan 14, 2013 9:51:39 AM by  Daniel Zobel [Product Manager]



Votes:

0

For me the script threw errorlevel 0 even if the Host was unreachable. This is due to the Timeout of the Ping.

Adding "-w 2500" to the ping solved the Problem for me and now the script works.

@echo off PING -w 2500 %1 > nul if errorlevel 1 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)

Created on Feb 24, 2021 8:28:51 AM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.