File: ptkwhois

package info (click to toggle)
ptknettools 0.2.3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 96 kB
  • ctags: 19
  • sloc: perl: 649; makefile: 34
file content (141 lines) | stat: -rwxr-xr-x 3,618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
# ptkwhois v0.2
# A Whois Client for Perl/Tk
# By Alan Ford <alan@whirlnet.co.uk> 17/04/99
#
# Changelog:
# 17/04/1999 Initial Release Version (0.1)
# 06/06/1999 Added support for command-line host and server specification (0.2)
#
# Distributed with no warranty under the GNU Public License

require 5.002;
use IO::Socket;
use Socket;
use English;
use Tk;
use Tk::DialogBox;
sub whois ;
sub help ;

my $version = "0.2";

my $default_server = "whois.internic.net";

my $MW = MainWindow->new;

$MW->title("Perl/Tk Whois");
$MW->Label(-text => "Version $version - Written by Alan Ford <alan\@whirlnet.co.uk>")->pack(-side => 'bottom');

my $lookup_frame = $MW->Frame()->pack(-expand => '1', -fill => 'both', -side => 'top');

$lookup_frame->Label(-text => "Whois Server:")->pack(-side => 'left');
my $lookup_server = $lookup_frame->Entry(-width => '20', -relief => 'sunken')->pack(-side => 'left', -expand => '1', -fill => 'x');
$lookup_frame->Label(-text => "Domain to Lookup:")->pack(-side => 'left');
my $lookup_host = $lookup_frame->Entry(-width => '20', -relief => 'sunken')->pack(-side => 'left', -expand => '1', -fill => 'x');

$lookup_server->insert('0', $default_server);

my $whois = $lookup_frame->Button(-text => 'Lookup Domain',
                                  -command => sub
    		                  {
			           whois;
			          });
$whois->pack(-side => 'left', -expand => '1', -fill => 'both');

my $exit = $lookup_frame->Button(-text => 'Exit',
                                 -command => sub
		                 {
		                  exit;
		                 });
$exit->pack(-side => 'left', -expand => '1', -fill => 'both');

my $scroll = $MW->Scrollbar();
$scroll->pack(-side => 'right', -fill => 'y');
my $display = $MW->Text(-height => '20', -width => '80', -yscrollcommand => ['set', $scroll])->pack(-side => 'bottom', -expand => '1', -fill => 'both');
$scroll->configure(-command => ['yview', $display]);

if ($ARGV[0]) {
   # Are they asking for help?
   if ($ARGV[0] =~ /help$/) {
       help;
   }
   if ($ARGV[0] eq "-?") {
       help;
   }
   if ($ARGV[0] eq "-h") {
       help;
   }
   my $cmdhost = $ARGV[0];
   my $cmdserver;
   if ($ARGV[1]) {
      $cmdserver = $ARGV[1];
   } else {
      $cmdserver = $default_server;
   }
   $lookup_host->insert('0', $cmdhost);
   $lookup_server->delete('0', 'end');
   $lookup_server->insert('0', $cmdserver);
   whois;
}

MainLoop;


sub whois {
$display->delete('1.0', 'end');

my $host = $lookup_host->get;
my $server = $lookup_server->get;
if ($server eq "") { 
    $server = $default_server;
    $lookup_server->insert('0', $default_server);
}
my $msg;

my $remote = IO::Socket::INET->new(
    	       Proto    => "tcp",
    	       PeerAddr => $server,
    	       PeerPort => "whois(43)",
      	      ); 

unless ($remote) { 
    $msg = "Cannot connect to $server\n";
    $display->insert('end', $msg);
    next;
}

$remote->autoflush(1);

# use CRLF network line terminators
print $remote "$host\015\012";

while ($_ = <$remote>) {
    #print;
    $_ =~ s/\r$//;  # trim annoying \r line-endings on some output
    $display->insert('end', $_);
}
close($remote)	or sub {
    $msg = "Can't close socket: $!\n";
    $display->insert('end', $msg);
    };
}

sub help {
   print <<EOF

ptkfinger - Perk/Tk Whois Client for X version $version (requires Perl/Tk)

Optional Parameters: [domain [server]]

domain being the domain to look up, server being the whois server to use
(default is $default_server)

Report bugs to the author, Alan Ford <alan\@whirlnet.co.uk>

For more information: `man ptkwhois'

EOF
;
exit;
}