|
Packit |
667938 |
#!/usr/bin/perl
|
|
Packit |
667938 |
##################################################################
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# Copyright (c) 1997 by Balthasar Indermuehle <balthasar@indermuehle.com>
|
|
Packit |
667938 |
# Currently supports Linux 2.0.25
|
|
Packit |
667938 |
# All Rights Reserved.
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
# See the file COPYRIGHT in the distribution for the exact terms.
|
|
Packit |
667938 |
# Based on the mrtg-ping-probe script Copyright 1997 by Peter W. Osel <pwo@guug.de>
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
##################################################################
|
|
Packit |
667938 |
require 5.003;
|
|
Packit |
667938 |
use Getopt::Std;
|
|
Packit |
667938 |
use File::Basename;
|
|
Packit |
667938 |
use Config;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
$ProgName = "mrtg-blast";
|
|
Packit |
667938 |
$Usage = "Usage: $ProgName hostname portnumber packets\nTypically: $ProgName my.host.com 9 500\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# Parse Command Line:
|
|
Packit |
667938 |
die $Usage unless getopts('');
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if (@ARGV > 3) {
|
|
Packit |
667938 |
print STDERR "$ProgName: WARNING: ignoring but the first three arguments\n";
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
if (@ARGV < 3) {
|
|
Packit |
667938 |
print STDERR "$ProgName ERROR:\nPlease enter a hostname port number and packets to blast (e.g. 9 or 21) as argument\n";
|
|
Packit |
667938 |
print STDERR "$Usage";
|
|
Packit |
667938 |
exit(1);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
|
|
Packit |
667938 |
($HostToBlast, $PortToBlast, $Packets) = @ARGV;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
($blastres) = blast($HostToBlast, $PortToBlast, $Packets);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# The external mrtg probe returns up to 4 lines of output:
|
|
Packit |
667938 |
# 1. Line: current state of the 'incoming bytes counter'
|
|
Packit |
667938 |
# 2. Line: current state of the 'outgoing bytes counter'
|
|
Packit |
667938 |
# 3. Line: string, telling the uptime of the target.
|
|
Packit |
667938 |
# 4. Line: telling the name of the target.
|
|
Packit |
667938 |
# We leave out line 3, and 4.
|
|
Packit |
667938 |
|
|
Packit |
667938 |
print "$blastres\n$blastres\n";
|
|
Packit |
667938 |
|
|
Packit |
667938 |
exit(0);
|
|
Packit |
667938 |
|
|
Packit |
667938 |
##################################################################
|
|
Packit |
667938 |
# Do the actual blasting
|
|
Packit |
667938 |
#
|
|
Packit |
667938 |
sub blast {
|
|
Packit |
667938 |
my($host, $port, $packets) = @_;
|
|
Packit |
667938 |
|
|
Packit |
667938 |
# The following path to tcpblast needs to be adjusted for your system
|
|
Packit |
667938 |
unless (open(BLAST, "/home/netadmin/mrtg-2.1/tcpblast -r -t $host $packets -p$port|")) {
|
|
Packit |
667938 |
print STDERR "${ProgName}: FATAL: Can't open tcpblast: $!";
|
|
Packit |
667938 |
exit(1);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
while (<BLAST>) {
|
|
Packit |
667938 |
# Handle output from 'real' tcpblast which looks like this:
|
|
Packit |
667938 |
# 100 KB in 1979 msec = 413946.4 b/s = 51743.3 B/s = 50.5 KB/s
|
|
Packit |
667938 |
close(BLAST), return("$4.$5") if /^(\d+) KB in (\d+) msec = (\d+)\.\d b\/s = (\d+)\.\d B\/s = (\d+)\.\d KB\/s/;
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|
|
Packit |
667938 |
#Could not get blast results, link may be down, return 0
|
|
Packit |
667938 |
close(BLAST), return(0);
|
|
Packit |
667938 |
}
|
|
Packit |
667938 |
|