Guest User

wtfisthis

a guest
Feb 4th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. Xchat::register( "geo-ip", "v0", "geo-ip", "" );
  4. Xchat::hook_print('Channel Message', "geoip");
  5. Xchat::hook_print('Your Message', "geoip");
  6. Xchat::print "Started: geo-ip v0";
  7.  
  8. use Net::DNS;
  9. use Switch;
  10. use Geo::IP;
  11.  
  12. my $trigger_word='!ip'; # Geo-IP public trigger to respond to.
  13. my $fite_word='!jfite'; # public trigger to make me fite someone
  14. my $database_filename = '/home/jas/Downloads/GeoLiteCity.dat'; # Path to the geoip database
  15. my @trigger_chans = qw(\#Soylent \#test \#fite); # Chans to respond to triggers.
  16.  
  17.  
  18. sub geoip
  19. {
  20.  
  21. #Just testing stuff here.
  22. if($_[0][1] =~ /fart/i) { Xchat::command("me farts for about thirty seconds ending in a liquid shart"); }
  23. # elsif($_[0][1] =~ /systemd/i) { Xchat::command("say oh no, $_[0][0], not this systemd shit again");}
  24. elsif($_[0][1] =~ /debug/i) { Xchat::command("say the incoming message from $_[0][0] was '$_[0][1]'");}
  25. #end of testing stuff.
  26.  
  27.  
  28.  
  29. my $cur_chan = Xchat::get_info('channel');
  30. if ((grep { $cur_chan =~ /$_/} @trigger_chans)) { # String contains a trigger @
  31. $_[0][1] =~ s/\s+/ /g; # Remove multiple spaces
  32. my @rowr = split(/ /,$_[0][1]);
  33. if (lc($rowr[0]) eq $trigger_word) {
  34. if (not defined $rowr[1]) {
  35. Xchat::command("say No IP supplied - use $trigger_word IP");
  36. return Xchat::EAT_NONE;
  37. }
  38. my $ip = $rowr[1];
  39.  
  40. my $rr, my $hostname;
  41.  
  42. my $res = Net::DNS::Resolver->new;
  43. my $query = $res->query($ip);
  44. if ($query) {
  45. foreach $rr ($query->answer) {
  46. next unless $rr->type eq "PTR";
  47. $hostname = $rr->ptrdname;
  48. }
  49. }
  50. my $gi = Geo::IP->open($database_filename, GEOIP_STANDARD);
  51. my $record = $gi->record_by_addr($ip);
  52. my $j_country_name = $record->country_name;
  53. my $j_region_name = $record->region_name;
  54. my $j_city = $record->city;
  55. my $j_postal_code = $record->postal_code;
  56. my $j_latitude = $record->latitude;
  57. my $j_longitude = $record->longitude;
  58. my $j_time_zone = $record->time_zone;
  59. 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");
  60. }
  61. elsif (lc($rowr[0]) eq $fite_word) { Xchat::command("say \#fite $rowr[1]");
  62. }
  63. }
  64. return Xchat::EAT_NONE;
  65. }
Add Comment
Please, Sign In to add comment