#!/usr/bin/perl
###############
#
# Autor: Ingo Walz
# Kontakt: [EMAIL=ingo@j-jayz-z.de]ingo@j-jayz-z.de[/EMAIL]
# Website: http://j-jayz-z.de
#
#Description:
#
#Dieses Script ist in der Lage, mit einer grafischen
#Oberfläche Hosts zu pingen und ihre Domain/Hostnamen in IP&´s
#aufzulösen und umgekehrt. Ich habe es bisher nur unter Windows
#getestet. Es ist allerdings Plattformunaghängig programmiert.
#Sollte also auch auf Linux laufen.
#
#
#
#Dieses script kann frei genutzt und verbreitet werden.
################
use warnings;
use strict;
#Module einbinden
use Tk;
use Net::Ping;
use Socket;
#Offene Konsole in Windows vermeiden
BEGIN {
if ($^O eq 'MSWin32')
{
require Win32::Console;
Win32::Console::Free();
}
}
#Ping Objekt erzeugen
my $p=Net::Ping->new('icmp');
#Hauptfenster erzeugen
my $main = MainWindow->new(-background => 'green');
#$main->overrideredirect(1);
#Frame erzeugen für Radiobuttons
my $main1 = $main->Frame(-width=> '25', -height=>'15')->pack();
#Haupttext
my $text = $main->Label( -text => "Bitte IP oder Hostnamen eingeben!",
-background => 'green')->pack();
#Eingabefeld erzeugen
my $input = $main->Entry(-background => 'grey', -foreground => 'red')->pack();
#Radio Variable erzeugen
my $radio_select = "0";
#Radiobuttons erzeugen
my $radio1 = $main1->Radiobutton(-text => "Ping", -background => 'green', -selectcolor => 'red', -value => '1', activebackground => 'red', -variable => \$radio_select)->pack(-side => 'left');
my $radio2 = $main1->Radiobutton(-text => "IP/Host", -background => 'green', -selectcolor => 'red', -value => '2', -activebackground => 'red', -variable => \$radio_select)->pack(-side => 'left');
my $radio3 = $main1->Radiobutton(-text => "Host/IP", -background => 'green', -selectcolor => 'red', -value => '3', -activebackground => 'red', -variable => \$radio_select)->pack(-side => 'left');
#Button erzeugen
my $button_ok = $main->Button( -text => 'Send!',
-relief => 'groove',
-activebackground => 'yellow',
-background => 'green',
-command => \&look,
)->pack(-side => 'left');
my $button_exit => $main->Button(-text => 'Exit',
-relief => 'groove',
-activebackground => 'yellow',
-background => 'green',
-command => sub { exit 0; }
)->pack(-side => 'right');
my $button_clear => $main->Button(-text => 'Clear',
-relief => 'groove',
-activebackground => 'yellow',
-background => 'green',
-command => sub {$input->delete(0, 'end')}
)->pack(-side => 'right');
#TK Programm ausführen
MainLoop();
#Subroutine look erzeugen
sub look {
if (!$radio_select)
{
#Popup für keine gewählte Funktion
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "Bitte Funktion wählen!",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
#Ping Funktion erzeugen
if ($radio_select == 1)
{
my $ping_host = $input->get();
my $error;
my $ping_okay;
if ($ping_host !~ /\d\d?\d?\.\d\d?\d?\.\d\d?\d?/ && $ping_host !~ /[A-Za-z0-9\.]+/ )
{
$error = "Die IP muss aus Zahlen bestehen!\n Der Hostname muss aus Zahlen oder Buchstaben bestehen!\n";
}
else
{
my $host = "$ping_host";
if ($p->ping($host))
{
$ping_okay = "\n$host ist erreichbar!\n";
$error="0";
}
else
{
$ping_okay = "\n$host ist nicht erreichbar!\n";
$error="0";
}
}
my $popup = $main->Toplevel(-background => 'green');
if ($error)
{
$popup->Label(-text => "$error",
-background => 'green')->pack();
}
else
{
$popup->Label(-text => "$ping_okay",
-background => 'green')->pack();
}
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
#IP/Host Funktion erzeugen
if ($radio_select == 2)
{
my $ping_host = $input->get();
my $host = $ping_host;
if ($host)
{
my $name = gethostbyaddr(inet_aton($host), AF_INET);
if ($name)
{
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "$name",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
else
{
my $error = "Konnte $host nicht auflösen!";
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "$error",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
$radio_select = "0";
}
}
else
{
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "Bitte IP eingeben!",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
}
#Host/IP Funktion erzeugen
if ($radio_select == 3)
{
my $ping_host = $input->get();
my $host = $ping_host;
if ($host)
{
my $name = inet_ntoa(inet_aton($host));
if ($name)
{
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "$name",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
else
{
my $error = "Konnte $host nicht auflösen!";
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "$error",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
$radio_select = "0";
}
}
else
{
my $popup = $main->Toplevel(-background => 'green');
$popup->Label(-text => "Bitte Domain oder Hostnamen eingeben!",
-background => 'green')->pack();
$popup->Button(-text => 'close',
-background => 'green',
-command => sub { $popup->destroy() } )->pack();
}
}
}