8 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
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',
);
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use strict;
use StFunc;
our %provider_cache = ();
my $ip = '217.118.85.66';
detect_ip($ip); #Ist in StFunc.pm defined
# %provider_cache wird befüllt mit angaben 'Provider' => '1'
# while weiter ist nur zum testzweck hier um zu sehen wird die IP erkannt oder nicht (0 oder 1 ergibt)
while(my($prv, $ip) = each(%provider_cache))
{
print "$prv => $ip\n";
}
exit;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/perl
use strict;
use warnings;
my %hash = (test => 1, hallo => 2, dies => 3, ist => 4, ein => 5, welt => 6);
my $counter = 0;
while( my ($key,$val) = each %hash){
print $key, "//", $val,"\n";
# das "keys %hash" dient dem Reset!
keys %hash and last if ++$counter == 2;
}
print "dazwischen\n";
while( my ($key,$val) = each %hash){
print $key, "//", $val,"\n";
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
}
8 Einträge, 1 Seite |