A.10. netzstatus.cgi

Dateiname: /usr/local/httpd/htdocs/admin/netzstatus.cgi.


#!/usr/bin/perl

print "Content-type: text/html\n\n";

my $uhrzeit = localtime();

print <<HTML;
<html>
<head>
  <title>Netzstatus</title>
</head>
<body>
<h1>Netzstatus</h1>

<i>$uhrzeit</i><p>

<table border="1">
<tr><th>Host</th><th>Beschreibung</th><th>Erreichbar?</th></tr>
HTML

my %hosts;
my %reachable;
$hosts{"192.168.0.1"} = "server";
$hosts{"192.168.0.136"} = "Access Point";
$hosts{"192.168.0.137"} = "PrintServer R23 hpdj930c";
$hosts{"192.168.0.138"} = "Drucker magicolor 2350 R23";
$hosts{"192.168.0.139"} = "Drucker OkiPage R23";
$hosts{"192.168.0.254"} = "Drucker HP LJ5 R104";

foreach (keys(%hosts)) {
  my $ip = $_;
  system("ping -nc1 $ip > /dev/null 2>&1");
  my $ret = $?;
  $reachable{$ip} = not $ret;
}

foreach (keys(%hosts)) {
  my $ip = $_;
  print qq(<tr><td>$ip</td><td>$hosts{$ip}</td>);
  print qq(<td bgcolor="green">Ja</td>) if ($reachable{$ip});
  print qq(<td bgcolor="red">Nein</td>) if (not $reachable{$ip});
  print qq(</tr>);
}

print <<HTML;
</table>
</body>
</html>
HTML

A.10.1. Hilfsprogramm ping.pl

Dateiname: /usr/local/sbin/ping.pl.


#!/usr/bin/perl

use Net::Ping;

my $host = shift || "127.0.0.1";
chomp($host);

print $host;

my $p = Net::Ping->new("icmp");

if ($p->ping($host)) {
  print "\t1\n";
} else {
  print "\t0\n";
}

$p->close();