Bon, voilà. Un petit script inutile qui vous permet de savoir (à peu près) où habitent les gens avec qui vous parlez et l'heure qu'il est chez eux.
Edit : le script qui suit est parfaitement inutile, et peut être avantageusement remplacé par
/ctcp <pseudo> time, néanmoins, il fut amusant à écrire.
# Print the country name and the local time in /WHOIS replies
# Based on : country.pl by Timo Sirainen
# This script uses the IP-to-Country Database
# provided by WebHosting.Info (http://www.webhosting.info),
# available from http://ip-to-country.webhosting.info.
# Install :
# 1. Get the latest ip-to-country database at :
# http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip
# and put it in ~/.irssi/scripts
# 2. Make a backup of your config files.
# 3. type (for instance):
# /format whois {nick $0} {nickhost $1@$2}%:{whois country $whois_country}%:{whois local $whois_local_time}%:{whois ircname $3}
# 4. Save the changes with /save
# Enjoy !
use strict;
use Irssi ;
use LWP::UserAgent;
use Socket;
use vars qw($VERSION %IRSSI);
$VERSION = "1.0.1";
%IRSSI = (
authors => "Yannick_LM",
contact => "yannicklm1337\@gmail.com",
name => "whois_local_time",
description => "Print the country name and the local time in /WHOIS replies",
license => "Public Domain",
changed => "Feb 8 2008"
);
our $HOME_DIR = $ENV{HOME};
our $GEOFILE = "$HOME_DIR/.irssi/scripts/ip-to-country.csv";
our $URL="http://www.worldtimeserver.com/";
our $time = "";
our $country ="";
# The last version of the file can be obtained there:
# http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip
# Convert IP to number for use in the ip-to-country database.
sub ip_to_number {
my $ip = shift;
my (@octets, $ip_num);
$ip =~ s/\n//g;
@octets = split /\./, $ip;
$ip_num = 0;
foreach (@octets) {
$ip_num <<= 8;
$ip_num |= $_;
}
return $ip_num;
}
# Find the country name and code in the database
sub find_country {
my $ip=shift;
$ip = &ip_to_number($ip);
open GF, "<$GEOFILE" or die "Can't open $GEOFILE $!";
while (<GF>){
$_ =~ s/"//g;
$_ =~ s/\n//;
my ($start, $end, $CC, $CTRY);
($start, $end, $CC, $CTRY, $country) = split /,/, $_;
if (($ip >= $start) and ($ip <= $end)){
return "$CC";
last;
}
}
close GF;
die "Country no found in database";
}
sub find_time {
my $CC=shift;
# Queries worltimeserver.com
my $ua = new LWP::UserAgent;
$ua->agent("AgentName/0.1 " . $ua->agent);
my $req = new HTTP::Request GET => "$URL/current_time_in_$CC.aspx";
my $res = $ua->request($req);
my $content = $res->content;
my @lines = split("\n", $content);
# Parses the result
foreach(@lines) {
if ( $_ =~ /\s+(\d\d?:\d\d (A|P)M)/ ) {
return $1;
}
}
}
# Redirect whois signal
sub sig_whois {
my ($server, $data, $nick, $host) = @_;
my ($me, $nick, $user, $host) = split(" ", $data);
$host =~ s/^.*\@//;
eval {
# if it's a cloack, there is a slash in the host
if ($host =~ m,/,) {
die "$host is a cloak";
}
else {
# Else, find the IP adress
my $packed_ip = gethostbyname("$host");
defined $packed_ip or die "gethostbyname failed :(";
my $ip = inet_ntoa($packed_ip);
# Find coutry and time
my $CC = &find_country($ip);
$time = &find_time($CC);
}
};
if ($@) {
# Irssi::active_win->print("Error : $@"); # Debug > merci de décommenter ceci si vous avez des problèmes
$country="Not Found";
$time="Unknown";
}
}
# For use in the /format ligne
sub expando_whois_local_time {
return $time;
}
sub expando_whois_country {
return $country;
}
Irssi::signal_add_first('event 311', \&sig_whois);
Irssi::expando_create('whois_local_time', \&expando_whois_local_time,
{ 'event 311' => 'None' } );
Irssi::expando_create('whois_country', \&expando_whois_country,
{ 'event 311' => 'None' } );
Pour les non-anglophones :
1. Sauvegardez le fichier dans .irssi/scripts/autorun/whois_local_time.pl
2. téléchargez la base de données ip-to-country
http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip, et extrayez-la dans .irssi/scripts
3. Sauvegardez vos fichiers de configuration
4. Tapez : /format whois {nick $0} {nickhost $1@$2}%:{whois country $whois_country}%:{whois local $whois_local_time}%:{whois ircname $3}
5. Tapez /save
Retours, remarques, suggestions bienvenues.