#!/usr/local/bin/perl -w use strict; use Tk; use Socket; my ($remote,$port, $iaddr, $paddr, $proto, $line); $remote = 'nujoma.perrins'; $port = 9216; $iaddr = inet_aton($remote) || die "no host: $remote"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); my $EOL = "\015\012"; sub dial { socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; select SOCK; $| = 1; select STDOUT; my $line = ; if ($line =~ /^\+/) { print SOCK "DIAL$EOL"; } $line = ; my $lock = $1 if $line =~ /([0-9.:]+)/; close SOCK; return $lock; } sub redial { socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; select SOCK; $| = 1; select STDOUT; my $line = ; if ($line =~ /^\+/) { print SOCK "FDIA$EOL"; } close SOCK; } sub drop { my $lock = shift; socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; select SOCK; $| = 1; select STDOUT; my $line = ; if ($line =~ /^\+/) { print SOCK "DROP $lock$EOL"; } close SOCK; } sub check { my $route = 0; socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!"; select SOCK; $| = 1; select STDOUT; my $line = ; if ($line =~ /^\+/) { print SOCK "ROUT$EOL"; while () { if (/ppp0/) { $route = 1; } } } close SOCK; return $route; } sub up_text { my $frame = shift; $_->destroy for $frame->children(); $frame->Label(-text=>'The connection has been made.')->pack; $frame->Label(-text=>'You may begin using the Internet.')->pack; $frame->parent->title('Rdial (connected)'); } sub down_text { my $frame=shift; $_->destroy for $frame->children(); $frame->Label(-text=>'The connection is underway. Wait a few')->pack; $frame->Label(-text=>'seconds for the dialup to work and use')->pack; $frame->Label(-text=>'your connection. You may click the')->pack; $frame->Label(-text=>'Test button to test the connection or')->pack; $frame->Label(-text=>'the Done button to finish using the connection.')->pack; $frame->parent->title('Rdial (not connected)'); } my $lock = dial; my $win = new MainWindow; $win->title('Rdial (connecting)'); my $top = $win->Frame->pack; my $stat = $win->Frame->pack; my $bf = $win->Frame->pack; my $redial = $bf->Button(-text=>'Reconnect', -command=> \&redial); my $mon; if (check) { up_text($top); } else { down_text($top); $mon = $win->repeat(1000, sub { if (check) { up_text($top); $mon->cancel(); } }); } $bf->Button(-text=>'Test', -command=>sub { if (check) { $stat->Label(-text=>'Connection is up and working.')->pack; $redial->packForget; } else { $redial->pack(-side=>'left'); $stat->Label(-text=>'Connection is not working.')->pack; } })->pack(-side=>'left'); $bf->Button(-text=>'Done', -command=>sub { drop($lock); $win->destroy; })->pack(-side=>'left'); MainLoop;