1 package Xchat::VPIT::Net;
6 use List::Util qw<max>;
7 use Locale::Country qw<code2country>;
11 use lib get_info 'xchatdir';
13 use Xchat::XPI::Net qw<resolve whois>;
15 our $VERSION = '0.02';
21 return unless defined;
23 if (s/^([^:]*)://) { $h{proto} = lc $1; }
24 ($_, my @path) = grep length, (split m!/!);
25 return unless defined;
26 if (s/:([0-9]*)$// && length $1) { $h{port} = $1; }
27 if (s/(.*)@([^@]*)$/$2/) { ($h{user}, $h{passwd}) = split /:/, $1, 2; }
29 $h{path} = \@path if @path;
34 my ($motif, $head, @strings) = @_;
35 $head = join ' ', ($motif x 3), $head, ($motif x 3);
37 my $l = max(map length, @strings) - length($head) - 1; # -1 for CR
38 $head .= ($motif x $l) if $l > 0;
40 print $ph "\002$head\n", @strings;
43 hook_command 'DIG', sub {
46 return EAT_ALL unless @reqs;
47 my @users = get_info('users');
48 my $context = get_context;
50 my $info = user_info $_;
51 my $req = parse_url($info ? $info->{host} : $_);
52 resolve $req->{host}, \&dig_print, [ $context, $req ];
56 help_text => 'DIG <ip(s)/hostname(s)>, resolve given names/addresses'
61 my ($context, $req) = @{$_[1]};
62 my $oldctxt = get_context;
67 output '-', 'Results for ' . $req->{host},
68 map { $_->string . "\n" } (@a, $p->authority, $p->additional);
70 output '*', 'Resolution failed for ' . $req->{host},
72 $_->mname . ' IN SOA ' . $_->rname . "\n",
73 join ' ', 'serial:' . $_->serial, 'ref:' . $_->refresh,
74 'ret:' . $_->retry, 'exp:' . $_->expire,
75 'min:' . $_->minimum . "\n";
76 } grep { $_->type eq 'SOA' } $p->authority;
79 print $ph 'Request ' . $req->{host} . " timed out\n";
84 hook_command 'NETWHOIS', sub {
87 return EAT_ALL unless @reqs;
88 my $context = get_context;
90 my $info = user_info $_;
91 my $req = parse_url($info ? $info->{host} : $_);
92 whois $req->{host}, \&netwhois_print, [ $context, $req ];
96 help_text => 'NETWHOIS <ip(s)/hostname(s)>, retrieve domain/ip information'
101 my ($context, $req) = @{$_[1]};
102 my $oldctxt = get_context;
103 set_context $context;
105 $raw =~ s/.*(Domain|inetnum)/$1/s;
106 $raw =~ s/[\r\n]*\>\>\>.*//s;
107 output '-', 'Results for ' . $req->{host},
111 } grep { !/^\s*(#|%)/ } split /\r?\n/, $raw;
113 output '*', 'No results for ' . $req->{host};
115 set_context $oldctxt;
118 hook_command 'TLD', sub {
121 return EAT_ALL unless @reqs;
123 my $info = user_info $_;
124 my $host = parse_url($info ? $info->{host} : $_)->{host};
125 my ($tld) = $host =~ /\.([a-z]+)\.*$/;
127 my $name = code2country $tld;
128 print $ph $tld . ' is ' . ($name ? $name : 'unknown') . "\n";
132 help_text => 'TLD <hostname(s)>, give the TLD text representation of the hosts'
135 $ph = Xchat::XPI->new(
136 name => 'Networking tools',
138 desc => 'DNS & Whois clients, TLD names',
139 author => 'Vincent Pit (VPIT)',
140 email => 'perl@profvince.com',
141 url => 'http://www.profvince.com',