New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How can I use PRTG to trace the route to a target?

Votes:

1

Your Vote:

Up

Down

Is it possible to show the IP of the hops for routing to a target?

custom-script-exe custom-sensor exe-script-sensor hops ip prtg traceroute tracert

Created on Nov 14, 2014 12:44:19 PM by  Arne Seifert [Paessler Support]

Last change on Mar 16, 2015 5:07:58 PM by  Martina Wittmann [Paessler Support]



12 Replies

Accepted Answer

Votes:

1

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 14 or later

Monitoring the IP Addresses of Hops

PRTG already comes with a Traceroute Hop Count sensor out of the box. Due to its static channel architecture, it is not feasible to create a sensor with one channel for each hop. You can use a small Powershell script to show the route in the sensor status message.

While limited to the sensor status message, which is not part of the historic data, the following script used with an EXE/Script Sensor shows the IPs of the hops.

param( [string]$target ) $trace=tnc $target -TraceRoute $count=[string]$trace.TraceRoute.Count foreach ($ip in $trace.TraceRoute) { $result=$result+$ip+" > " } $result=$result.Substring(0,$result.Length-3) $message=$count+" hops to reach "+$target+" via "+$result write-host $count":"$message

System Requirements

  1. Windows 8.1 or newer, or Server 2012 R2 or newer.

How to Use this Script

  1. Enable Powershell RemoteSigned execution policy on your system with this command: set-executionpolicy RemoteSigned
  2. Create a file with the extension .ps1, for example, "trace.ps1"
  3. Copy the above source code, paste it into the file, and save it.
  4. Save this file into the PRTG installation folder, subfolder \Custom Sensor\EXE. Note: This requires local Windows administrator rights.
  5. In PRTG, add an EXE/Script sensor to a device. Pick trace.ps1 from the list of scripts.
  6. Use the parameter field to enter the target, for example, www.paessler.com
  7. Save the configuration.

Created on Nov 14, 2014 1:10:10 PM by  Arne Seifert [Paessler Support]

Last change on Jun 16, 2015 12:55:33 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello support,

The result of sensor is :

"hops to reach www.paessler.com via"

But nothing else.

Also the sensor is green and the value is 0.

Can you help me?

Created on May 29, 2015 2:54:41 PM by  John Doe (0) 1



Votes:

0

Your Vote:

Up

Down

Here is the result of Sensor log:

---

Le terme « tnc » n'est pas reconnu comme nom d'applet de commande, fonction, fi
chier de script ou programme exécutable. Vérifiez l'orthographe du nom, ou si u
n chemin d'accès existe, vérifiez que le chemin d'accès est correct et réessaye
z.
Au niveau de D:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\tra
cert.ps1 : 4 Caractère : 11
+ $trace=tnc <<<<  $target -TraceRoute
    + CategoryInfo          : ObjectNotFound: (tnc:String) [], CommandNotFound 
   Exception
    + FullyQualifiedErrorId : CommandNotFoundException
 
: hops to reach www.paessler.com via 

---

Created on May 29, 2015 2:57:41 PM by  John Doe (0) 1

Last change on Jun 1, 2015 9:09:11 AM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Dear Yannick

I am sorry, your Windows seems to lack the tnc utility which was introduced with Windows 8.1 (or Server 2012 R2) as part of Powershell 4.0.

edit: I put a clarification in the original article.

Created on Jun 1, 2015 9:12:21 AM by  Arne Seifert [Paessler Support]

Last change on Jun 1, 2015 9:14:26 AM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

@Paessler Support
Thanks for the aboving script ,that is fine for trace the hops to destination.

I have one more question on this, how could I define the related script that could trace the PING reply times, such like bellowing "PingReplyDetails (RTT) : 105 ms"
PS C:\Windows\system32> tnc 8.8.8.8 -traceroute

ComputerName           : 8.8.8.8
RemoteAddress          : 8.8.8.8
InterfaceAlias         : Ethernet 4
SourceAddress          : 10.204.17.185
PingSucceeded          : True
PingReplyDetails (RTT) : 105 ms
TraceRoute             : 10.204.16.1
                         59.125.99.235
                         59.125.99.254
                         168.95.228.58
                         220.128.1.82
                         220.128.8.81
                         220.128.8.173
                         72.14.205.102
                         209.85.243.30
                         216.239.46.223
                         216.239.43.101
                         TimedOut
                         8.8.8.8

I already adjusted the the script and put it in the path of advanced script folder like bellowing for add 2 channels which including hops and response times rather than execution time, but it always returned "invalid point operation"

param(
  [string]$target
)
$trace=tnc $target -TraceRoute
$count=[string]$trace.TraceRoute.Count
$time=[string]$trace.PingReplyDetails
foreach ($ip in $trace.TraceRoute) {
$result=$result+$ip+" > "
}
$result=$result.Substring(0,$result.Length-3)
$message=$count+" hops to reach "+$target+" via "+$result
#write-host $count":"$message
#write-host $time
Write-Host '<prtg>'
Write-Host "<result>" 
"<channel>Response</channel>" 
"<value>"+ $time.Seconds +"</value>" 
"</result>"
Write-Host "<result>" 
"<channel>Hops</channel>" 
"<value>"+ $count +"</value>" 
"</result>"
Write-Host "</prtg>"

Does any support can help me on this ?
Thanks in advance.

Created on Jul 29, 2015 3:01:45 AM by  kelvin_xue (0) 1

Last change on Jul 29, 2015 9:06:23 AM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Dear Kelvin Xue

Our scripts provide a demonstration which can be expanded by users; however we offer no technical support for these scripts.

Please check what happens when you run the script from the command line. If the error appears in a particular line of code, please try to correct that line.

If you can run the script from the command line, but not as sensor, please open the sensor configuration and set the security context to use the credentials provided by the parent device. In addition, please open the settings tab of the according device an enter the Windows credentials the script should use.

Created on Jul 29, 2015 9:09:14 AM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

works on windows7 or windows 2008 r2

param(
  [string]$target
)
$target ="bso.at"
$trace = tracert -4 $target
$count = 0
$result = ""
foreach ($line in $trace) {
    if($line.contains(" ms") -or $line.contains(" * ") ) {
        $count = $count + 1
        $array = $line.trim() -split "\s+"
        $ip =  $array[7] + " " + $array[8]
        $result = $result + $ip.trim() + " > "
    }
}
$result = $result.Substring(0, $result.Length - 3)
$message = "$count" + " hops to reach " + $target + " via " + $result
write-host $count":"$message

Created on Nov 3, 2015 11:22:51 AM by  bso (0)



Votes:

1

Your Vote:

Up

Down

Sometimes you want to check which route is in use, e.g. there is a default and a failoder route:

# $Destination: IP/DNS
# $DefaultIP:	x.x.x.x, x.x.*.* IP within the default route
# $FailoverIP:	y.y.y.y, y.y.*.* IP within the failover route

param(
[string]$Destination,[string]$DefaultIP,[string]$FailoverIP
)

$CountDefaultIP = 0
$CountFailoverIP = 0
$Sum = 0

$Trace = Test-NetConnection $Destination -TraceRoute
$TraceCount = $Trace.TraceRoute.Count

For ($i = 0; $i -le $TraceCount-1; $i++) {
    $TraceValue = $Trace.TraceRoute.GetValue($i)
    If($TraceValue -like $DefaultIP) {
        $CountDefaultIP = $CountP1 + 1
		$Sum = 1		
    }
    If($TraceValue -like $FailoverIP) {
        $CountFailoverIP = 1
		$Sum = 2
    }
}

write-host "<?xml version=`"1.0`" encoding=`"UTF-8`"?>"
write-host "<prtg>"
write-host "<result>"
write-host "<channel>Route Status </channel>"
write-host "<value>$Sum</value>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMinError>0.5</LimitMinError>"
write-host "<LimitMaxWarning>1.5</LimitMaxWarning>"
write-host "</result>"
write-host "<result>"
write-host "<channel>Default $DefaultIP </channel>"
write-host "<value>$CountDefaultIP</value>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMinWarning>0.5</LimitMinWarning>"
write-host "</result>"
write-host "<result>"
write-host "<channel>Failover $FailoverIP </channel>"
write-host "<value>$CountFailoverIP</value>"
write-host "<LimitMode>1</LimitMode>"
write-host "<LimitMaxWarning>0.5</LimitMaxWarning>"
write-host "</result>"
write-host "</prtg>"

Created on Nov 12, 2015 4:31:49 PM by  Clemens Fürtbauer (130) 1



Votes:

0

Your Vote:

Up

Down

Sadly, both last script do not work for me on Windows Server 2012, could you or someone post the updates please?

I need to track overloaded machines on a trace to a destinations.

I am surprised that such a standard sensor like a qualified traceroute is not covered in standard sensors by Paessler.

Thanks in advance...peter

Created on Feb 6, 2017 3:00:42 PM by  pmx (0)



Votes:

0

Your Vote:

Up

Down

Dear Support,

Can i get the history of below Script, For example now it's showing me the hop count and the trace route to the destination, I want to log the trace if the route changes to get like history or something show me that route changes ? is is possible through this Script ?

Created on Mar 4, 2019 9:57:56 AM by  amro-shoufi (0)



Votes:

0

Your Vote:

Up

Down

Dear amro-shoufi,

please understand that custom scripts, even if posted by ourselves, are not covered by further technical support. The script itself does no logging or comparison with earlier traceroute runs. You might be able to add additional features.

Created on Mar 5, 2019 1:16:11 PM by  Arne Seifert [Paessler Support]

Last change on Mar 5, 2019 1:19:50 PM by  Arne Seifert [Paessler Support]



Votes:

5

Your Vote:

Up

Down

Invested 30 minutes and created the below script:

param(
  [string]$Target,
  [string]$ExpectedRoute
)

$ER = $ExpectedRoute.Split(",");

$Trace=TNC $Target -TraceRoute;
$Count=[string]$Trace.TraceRoute.Count;

$Message = "";
$asexpected = 1;
[int]$i = 0;
ForEach ($IP in $Trace.TraceRoute) {
    If ($i -lt $ER.Length){
        If ($IP.Trim() -ne $ER[$i].Trim()) {
            $Message = "Route change at HOP #" + ($i + 1).ToString() + " - IP expected: " + $ER[$i] + " - IP found: $IP";
            $asexpected = 0;
            break;
        }
    }
    $i += 1;
}

If ($Trace.TraceRoute.Count -ne $ER.Length) {
    If ($asexpected -eq 1) {
        $Message = "Route changed - expected HOP count: " + $ER.Length + " - detected HOP count: " + $Trace.TraceRoute.Count;
        $asexpected = 1;
    }
}

$reached = 0;
If ($Trace.PingSucceeded) {
    $reached = 1;
}


$XML = "<prtg>
    <result>
        <channel>Target reached</channel>
        <value>$reached</value>
        <LimitMode>1</LimitMode>
        <LimitMinError>1</LimitMinError>
    </result>
    <result>
        <channel>Round Trip Time</channel>
        <value>" + $Trace.PingReplyDetails.RoundtripTime + "</value>
    </result>
    <result>
        <channel>Total HOPs</channel>
        <value>" + $Trace.TraceRoute.Count + "</value>
    </result>
    <result>
        <channel>Route matches expected route</channel>
        <value>$asexpected</value>
        <LimitMode>1</LimitMode>
        <LimitMinError>1</LimitMinError>
        <LimitErrorMsg>$Message</LimitErrorMsg>
    </result>
</prtg>"

Function WriteXmlToScreen ([xml]$xml) #just to make it clean XML code...
{
    $StringWriter = New-Object System.IO.StringWriter;
    $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter;
    $XmlWriter.Formatting = "indented";
    $xml.WriteTo($XmlWriter);
    $XmlWriter.Flush();
    $StringWriter.Flush();
    Write-Output $StringWriter.ToString();
}

WriteXmlToScreen "$XML"

What you need as parameter is a target IP or DNS name - and a list of expected HOPs in between. The fact that you need to inject the expected HOPs bypasses that you would need some kind of a config-file or database.

It would not work if you write out a log-file - cause this log would only temporarily cause an error state and by the next check possible become the new norm.

Example for the parameters... please inject first the target host/IP and then a list of HOPs - comma separated - as IP addresses, including the target IP address.

10.1.1.1 "192.168.1.254,10.0.0.1,10.1.0.1,10.1.1.1"

This will actually do the following:

  • report back if the target was reachable
  • tell you the total roundtrip time to the target
  • show you the HOP count that was true (right now) towards the target
  • check if each of the injected IP HOPs stayed the same
    • if so no further message is shown
    • if a HOP is different, this will raise an error and report which HOP was found and which was expected
    • if the injected HOPs are all found but the amount was different, an error is raised and you see the difference of the HOP counts

This should help everyone with this challenge... the script might be able to be optimized, but it should be a rather good start...

Regards

Florian Rossmark

www.it-admins.com

Created on Mar 6, 2019 4:36:41 AM by  Florian Rossmark (4,110) 3 2



Please log in or register to enter your reply.


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.