html/dcc_ip.pl


   1 #!/usr/bin/perl -w
   2 # dcc_ip.pl v0.5 - Copyright (c) ak5 2004
   3 # License: Public Domain :-)
   4 #
   5 # this scripts gets the current IP before sending a dcc..
   6 # useful, if you connect through a BNC f.e.
   7 # just load it and it will do it's job if dcc_ip_interface is set correct.
   8 # 
   9 
  10 # This means: If you are connecting through a router:
  11 #          /set dcc_ip_interface router
  12 # (NOT the IP of your router, just the word "router".
  13 #
  14 # If you're on dialup or something other and you see your external
  15 # IP address listed in 'ifconfig's output, 
  16 #          /set dcc_ip_interface <interface>
  17 # (for example ppp0)
  18 #
  19 # requires: /sbin/ifconfig ;) If you have a router, you need lynx also.
  20 #
  21 ##########
  22 
  23 use Irssi;
  24 use vars qw($VERSION %IRSSI);
  25     $VERSION = '0.5';
  26     %IRSSI = (
  27         authors     => 'ak5',
  28         contact     => 'meister@hq.kroenk.remove-this-because-of-spam.de',
  29         name        => 'dcc_ip',
  30         description => 'This script sets dcc_own_ip when starting a DCC send or chat.'.
  31 		       'set dcc_ip_interface to your external interface, f.e. ppp0.'.
  32 		       'If you are connecting though a router, set it to "router"',
  33         license     => 'Public Domain',
  34 	url	    => 'http://hq.kroenk.de/?gnu/irssi',
  35 	source      => 'http://hq.kroenk.de/?gnu/irssi/dcc_ip.pl/plaintext',
  36 	changed     => 'Sa 26 Jun 2004 22:27:08 CEST',
  37     );
  38 
  39 sub dcc_ip {
  40     my ($args, $shash, $c, $iface, $cmd, @arg, @ip) = @_;
  41     @arg = split(" ", $args);
  42     if (@arg[0] eq "send" || @arg[0] eq "chat") {
  43         $iface = Irssi::settings_get_str('dcc_ip_interface');
  44 	
  45 	if ($iface eq "router") {
  46 		$cmd = `lynx -dump -nolist http://ipid.shat.net/iponly/`;
  47 		$cmd =~ s/[a-zA-Z:\ \n]//g;
  48 	} else {
  49 		$cmd = `/sbin/ifconfig $iface | head -n 2 | tail -n 1`;
  50 		$cmd =~ s/^[a-zA-Z\ ]*\://;
  51 		$cmd =~ s/\ .*$//;
  52 		$cmd =~ s/\n//;
  53 	}
  54 	Irssi::command("^set dcc_own_ip ".$cmd);
  55 
  56     }
  57 };
  58 
  59 Irssi::settings_add_str('dcc_ip', 'dcc_ip_interface', "ppp0");
  60 Irssi::command_bind ('dcc', 'dcc_ip');
  61 #EOF