our %providers = (
'Telecom1' => '80.80.105.0 - 80.80.111.255',
'Telecom2' => '83.136.112.0 - 83.136.112.255',
'IDEA (India)' => '203.145.137.160 - 203.145.137.191',
'Simobil (Slovenia)' => '80.95.224.0 - 80.95.228.255',
'Omar Monges (Lat. Amerika)' => '200.0.0.0 - 200.255.255.255',
'DataElectronics (Ireland)' => '217.114.160.0 - 217.114.175.255',
);
#Weiter muss man selbst es in Hash die Daten einlegen.
sub detect_ip {
my $ip = $_[0] or return 0;
my ($octA, $octB, $octC, $octD) = split(/\./, $ip);
my ($provider);
my (@explodes_ips);
my $unknown_ip_base = $config{'base_path'}.'/unknownip.txt';
my($f_a, $f_b, $f_c, $f_d);
my $found=0;
my %providers_hash = %providers;
while (my($provider_name, $ip_backbone) = each(%providers_hash))
{
if ($ip_backbone =~ /;/)
{
@explodes_ips = split(/;/, $ip_backbone);
foreach my $ips(@explodes_ips)
{
my($ip_start, $ip_end) = split(/ - /, $ips);
my($ip_start_A, $ip_start_B, $ip_start_C, $ip_start_D) = split(/\./, $ip_start);
my($ip_end_A, $ip_end_B, $ip_end_C, $ip_end_D) = split(/\./, $ip_end);
$f_a=detect_octet($octA, $ip_start_A, $ip_end_A);
$f_b=detect_octet($octB, $ip_start_B, $ip_end_B);
$f_c=detect_octet($octC, $ip_start_C, $ip_end_C);
$f_d=detect_octet($octD, $ip_start_D, $ip_end_D);
if ($f_a and $f_b and $f_c and $f_d) {
$provider_cache{$provider_name} += 1;
return 1;
}
}
} else {
my($ip_start, $ip_end) = split(/ - /, $ip_backbone);
my($ip_start_A, $ip_start_B, $ip_start_C, $ip_start_D) = split(/\./, $ip_start);
my($ip_end_A, $ip_end_B, $ip_end_C, $ip_end_D) = split(/\./, $ip_end);
$f_a=detect_octet($octA, $ip_start_A, $ip_end_A);
$f_b=detect_octet($octB, $ip_start_B, $ip_end_B);
$f_c=detect_octet($octC, $ip_start_C, $ip_end_C);
$f_d=detect_octet($octD, $ip_start_D, $ip_end_D);
if ($f_a and $f_b and $f_c and $f_d) {
$provider_cache{$provider_name} += 1;
return 1;
}
}
}
$provider_cache{'Unbekannt'} += 1;
# Nur für DEBUG
#if (! -f $unknown_ip_base)
#{
# open(UNK, ">$unknown_ip_base") or die('Cannot open '.$unknown_ip_base.' : '.$!);
# } else {
# open(UNK, ">>$unknown_ip_base") or die('Cannot open '.$unknown_ip_base.' : '.$!);
#}
#print UNK "$ip\n";
#close(UNK);
return 0;
}
sub detect_octet {
my ($ip_octet, $octet_a, $octet_b) = @_;
if ($ip_octet >= $octet_a and $ip_octet <= $octet_b)
{
return "1";
}
return 0;
}