#!/usr/bin/perl ######################################## # Name: Check Speedport # # # # Author: Kim-Norman Sahm # # Contact: kim-norman.sahm@t-online.de # # Version: 1.0 # # Licence: GPL # # Date: 08.01.2014 # # # # Tested: # # Speedport W 701V # ######################################## my $host; my $verbose; my $help; my $warn; my $crit; my $speed; my $wanip; ####################### use LWP::Simple; use Data::Dumper; use Net::Ping; use Getopt::Long; use strict; &check_options; if($help || !defined($host) || (!defined($wanip) && !defined($speed)) || (defined($speed) && !defined($crit) && !defined($warn))) { &help(); exit 3; } elsif(&check_hoststatus) { &get_status; } ###### SUB Start sub check_options { Getopt::Long::Configure ("bundling"); GetOptions( 'v' => \$verbose, 'verbose' => \$verbose, 'h' => \$help, 'help' => \$help, 'w:s' => \$warn, 'warn:s' => \$warn, 'c:s' => \$crit, 'crit:s' => \$crit, 'H:s' => \$host, 'hostname:s' => \$host, 'W' => \$wanip, 'wanip' => \$wanip, 'S' => \$speed, 'speed' => \$speed, ); } sub help { print "Check Speedport\n\n"; print "Usage:\n"; print " -H, --hostname [Host] Hostname\n"; print " -W, --wanip Check WAN-IP\n"; print " -S, --speed Check DSL downstream-/upstream-speed\n\n"; print "Check-Options (only -s/--speed):\n"; print " -w, --warn n,m Warn-level: downstream,upstream (KBit/s)\n"; print " -c, --crit n,m Crit-level: downstream,upstream (KBit/s)\n\n"; print " -v, --verbose Verbose Output\n"; print " -h, --help Show this Output\n\n"; print "Example: check WAN-IP\n"; print " .\/check_epson_speedport.pl -H speedport.ip -W\n"; print "Example: check DSL-Speed\n"; print " .\/check_epson_speedport.pl -H speedport.ip -S -w 3000,400 -c 1500,200\n"; } sub check_hoststatus { my $p = Net::Ping->new(); if($p->ping($host)) { print "$host is online.\n" if $verbose; return 1; } else { print "ERROR - Host is not online.\n"; exit 3; } $p->close(); } sub get_status { my $statussite = "http://$host/cgi-bin/webcm?getpage=../html/top_newstatus.htm"; my $site = get("$statussite"); if(defined($wanip)) { $site =~ m/