PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|Proxy|pingomatic-1.013.pl =

page 3 of 7



		"host=s@" => \@addhost,
		"ns|nameserver!" => \$do_ns,
		"d|debug!" => \$debug,
		"update|interval=i" => \$update,
		"log|logfile=s" => \$log,
	       )) {
    require Pod::Usage;
    Pod::Usage::pod2usage(1);
}

my @hosts;
if (defined $hostfile && -r $hostfile) {
    open(H, $hostfile) or die "Can't open $hostfile";
    @hosts = read_pingomatic_hosts(\*H);
    close H;
} elsif ($hostgroup eq 'empty') {
    @hosts = ();
} elsif ($hostgroup ne 'normal') {
    no strict 'refs';
    @hosts = &{"hostgroup_" . lc($hostgroup)};
} elsif (open(H, "$ENV{HOME}/.pingomatic.hosts")) {
    @hosts = read_pingomatic_hosts(\*H);
    close H;
} else {
    @hosts = hostgroup_default();
}

push @hosts, map { pingomatic_host($_) } @addhost;
push @hosts, map { pingomatic_host($_) } @ARGV if @ARGV;

if ($do_ns) {
    get_nameserver();
    push @hosts, map { [ $_, "name" ] } @nameserver;
}

my $term = new Term::ReadLine 'pingomatic';

my %pingdefs;

if ($debug) {
    open(STDERR, ">/tmp/pingomatic.debug");
} else {
    require File::Spec;
    open(STDERR, ">" . File::Spec->devnull);
}

my $clearchr;
if (eval { require Term::Cap }) {
    my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600 };
    $clearchr = $terminal->Tputs("cl");
}
if ($clearchr eq '') {
    # XXX MSWin32: use cls instead?
    $clearchr = `clear`;
}

foreach my $host (@hosts) {
    new_ping($host);
}

if ($log) {
    my $log_exists = -e $log;
    open $logfh, ">>$log" or die "Can't append to $log: $!"; # XXX STDERR is redirected already
    my $oldfh = select($logfh); $| = 1; select($oldfh);
    print_log_header() if not $log_exists;
}

show_ping_stat();

# start timers...
my $update_w =
    Event->timer(desc => "update",
		 interval => $update,
		 cb => \&show_ping_stat,
		 );

Event->timer(
	     interval => 20,
	     cb => \&try_later,
	    );

Event->io(
	  fd => \*STDIN,
	  poll => 'r',
	  cb => \&handle_key,
	  repeat => 1,
	 );

ReadMode 3;

Event::loop();

sub print_log_header {
    print $logfh join("\t", "Time", map { $pingdefs{$_}->host } sort keys %pingdefs) . "\n";
}

sub get_ping_line {
    my $e = shift;
    my $got = $e->got;
    my $fd = $e->w->fd;
=3=

1|2| < PREV = PAGE 3 = NEXT > |4|5|6|7

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.0118201 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)