From: bw1 Date: Sun, 17 Feb 2019 20:08:42 +0000 (+0100) Subject: [dcc_ip] change website with whois X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=73196ae9919deefa114388e4b722f308129fabc3;p=irssi-scripts.irssi.org.git [dcc_ip] change website with whois --- diff --git a/scripts/dcc_ip.pl b/scripts/dcc_ip.pl index 3c03bf3..3c7e8b8 100644 --- a/scripts/dcc_ip.pl +++ b/scripts/dcc_ip.pl @@ -22,10 +22,11 @@ use strict; use Irssi; +use Socket; use vars qw($VERSION %IRSSI); - $VERSION = '0.5'; + $VERSION = '0.6'; %IRSSI = ( - authors => 'ak5', + authors => 'ak5, bw1', contact => 'meister@hq.kroenk.remove-this-because-of-spam.de', name => 'dcc_ip', description => 'This script sets dcc_own_ip when starting a DCC send or chat.'. @@ -34,29 +35,83 @@ use vars qw($VERSION %IRSSI); license => 'Public Domain', url => 'http://hq.kroenk.de/?gnu/irssi', source => 'http://hq.kroenk.de/?gnu/irssi/dcc_ip.pl/plaintext', - changed => 'Sa 26 Jun 2004 22:27:08 CEST', + changed => '2019-02-17', ); +# ip of the nat interface as a string; +my $router_ip; +# state of whois +my $router_c=0; +# arguments of the dcc command +my $router_args; + sub dcc_ip { my ($args, $shash, $c, $iface, $cmd, @arg, @ip) = @_; @arg = split(" ", $args); if (@arg[0] eq "send" || @arg[0] eq "chat") { $iface = Irssi::settings_get_str('dcc_ip_interface'); - - if ($iface eq "router") { - $cmd = `lynx -dump -nolist http://ipid.shat.net/iponly/`; - $cmd =~ s/[a-zA-Z:\ \n]//g; - } else { - $cmd = `/sbin/ifconfig $iface | head -n 2 | tail -n 1`; - $cmd =~ s/^[a-zA-Z\ ]*\://; - $cmd =~ s/\ .*$//; - $cmd =~ s/\n//; - } - Irssi::command("^set dcc_own_ip ".$cmd); - + if ($router_c == 0) { + if ($iface eq "router") { + mywhois($args, $shash, $c); + Irssi::signal_stop(); + $router_c=1; + $router_args = $args; + return; + } else { + $cmd = `/sbin/ifconfig $iface | head -n 2 | tail -n 1`; + $cmd =~ s/^[a-zA-Z\ ]*\://; + $cmd =~ s/\ .*$//; + $cmd =~ s/\n//; + } + Irssi::command("^set dcc_own_ip ".$cmd); + } else { + $router_c =0; + } } }; +sub mywhois { + my ($args, $server, $witem) = @_; + my $nick =$server->{nick}; + $server->redirect_event("whois", 1, $nick, 0, undef, { + "event 311" => "redir whos", + "event 318" => "redir whosend", + "" => "event empty"} + ); + $server->send_raw("WHOIS " . $nick); +} + +sub sig_whos { + my ($server, $data) = @_; + my @r = split(/\s/,$data); + $router_ip = $r[3]; +} + +sub sig_whosend { + my ($server, $data) = @_; + + if ( defined $router_ip ) { + if ( !( $router_ip =~ m/\d+\.\d+\.\d+\.\d+/ || + ($router_ip =~ m/[0-9a-fA-F:]+/ && $router_ip =~ m/:.*:/ ))) { + my $packed_ip = gethostbyname($router_ip); + if (defined $packed_ip) { + $router_ip = inet_ntoa($packed_ip); + } else { + $router_ip = undef; + } + } + } + if ( defined $router_ip ) { + Irssi::settings_set_str("dcc_own_ip", $router_ip); + $server->command('dcc '.$router_args ); + } +} + +Irssi::signal_add('redir whos', \&sig_whos); +Irssi::signal_add('redir whosend', \&sig_whosend); + Irssi::settings_add_str('dcc_ip', 'dcc_ip_interface', "ppp0"); Irssi::command_bind ('dcc', 'dcc_ip'); #EOF + +# vim:set ts=8 sw=4 expandtab: