Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- Xchat::register( "geo-ip", "v0", "geo-ip", "" );
- Xchat::hook_print('Channel Message', "geoip");
- Xchat::hook_print('Your Message', "geoip");
- Xchat::print "Started: geo-ip v0";
- use Net::DNS;
- use Switch;
- use Geo::IP;
- my $trigger_word='!ip'; # Geo-IP public trigger to respond to.
- my $fite_word='!jfite'; # public trigger to make me fite someone
- my $database_filename = '/home/jas/Downloads/GeoLiteCity.dat'; # Path to the geoip database
- my @trigger_chans = qw(\#Soylent \#test \#fite); # Chans to respond to triggers.
- sub geoip
- {
- #Just testing stuff here.
- if($_[0][1] =~ /fart/i) { Xchat::command("me farts for about thirty seconds ending in a liquid shart"); }
- # elsif($_[0][1] =~ /systemd/i) { Xchat::command("say oh no, $_[0][0], not this systemd shit again");}
- elsif($_[0][1] =~ /debug/i) { Xchat::command("say the incoming message from $_[0][0] was '$_[0][1]'");}
- #end of testing stuff.
- my $cur_chan = Xchat::get_info('channel');
- if ((grep { $cur_chan =~ /$_/} @trigger_chans)) { # String contains a trigger @
- $_[0][1] =~ s/\s+/ /g; # Remove multiple spaces
- my @rowr = split(/ /,$_[0][1]);
- if (lc($rowr[0]) eq $trigger_word) {
- if (not defined $rowr[1]) {
- Xchat::command("say No IP supplied - use $trigger_word IP");
- return Xchat::EAT_NONE;
- }
- my $ip = $rowr[1];
- my $rr, my $hostname;
- my $res = Net::DNS::Resolver->new;
- my $query = $res->query($ip);
- if ($query) {
- foreach $rr ($query->answer) {
- next unless $rr->type eq "PTR";
- $hostname = $rr->ptrdname;
- }
- }
- my $gi = Geo::IP->open($database_filename, GEOIP_STANDARD);
- my $record = $gi->record_by_addr($ip);
- my $j_country_name = $record->country_name;
- my $j_region_name = $record->region_name;
- my $j_city = $record->city;
- my $j_postal_code = $record->postal_code;
- my $j_latitude = $record->latitude;
- my $j_longitude = $record->longitude;
- my $j_time_zone = $record->time_zone;
- Xchat::command("say IP: ($ip) Hostname: $hostname Country: $j_country_name Region: $j_region_name City: $j_city Zip Code: $j_postal_code Latitude: $j_latitude Longitude: $j_longitude Time Zone: $j_time_zone");
- }
- elsif (lc($rowr[0]) eq $fite_word) { Xchat::command("say \#fite $rowr[1]");
- }
- }
- return Xchat::EAT_NONE;
- }
Add Comment
Please, Sign In to add comment