All the files

This commit is contained in:
2024-03-09 15:36:42 +01:00
parent 58e88da2d8
commit 08b6b503a6
22 changed files with 1721 additions and 0 deletions

40
lib/geoip.pm Normal file
View File

@@ -0,0 +1,40 @@
package My::parser::geoip;
use strict;
use warnings;
use IO::Socket::INET;
sub new {
my $class = shift;
my $self = {};
bless ($self,$class);
$self->{'config'} = shift;
my $config = $self->{'config'};
$config->{'logger'}->log('Loaded My::parser::geoip');
return $self;
}
sub parse {
my $self = shift;
my $host = shift;
return unless($host =~ m/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/);
$| = 1;
my $socket = new IO::Socket::INET (
PeerHost => '10.0.0.100',
PeerPort => '7777',
Proto => 'tcp'
);
$self->{'config'}->{'logger'}->log("Failed to look up GeoIP for $host, could not connect to GeoIP resolver") unless $socket;
return { asn => 0, iso => '' } unless $socket;
my $size = $socket->send($host."\n");
my $response;
$socket->recv($response, 1024);
shutdown($socket,1);
$socket->close;
my ($asn,$iso) = split (",", $response);
my $r = {};
$r->{'asn'} = $asn;
$r->{'iso'} = $iso;
return $r;
}
1;