Thread Soll man den hash "resetten" ?: Suche die Lösung für %Hash (7 answers)
Opened by polkana at 2006-12-30 13:27

polkana
 2006-12-30 17:30
#72812 #72812
User since
2004-06-18
74 Artikel
BenutzerIn
[Homepage] [default_avatar]
Dank Ihre Hilfe gebe ich die Source code. Villeicht hat jamand das schon geschrieben?
Na was solls..
Ich habe endlich nun nachgedacht dass man einfach kopieren in extra %hash kann.
Nun geht keine IP mehr unerkannt ;)

Die Code ermöglicht feststellen Providername, wenn man eine IP voliegt.
Kritick ist nicht abgeschlossen :) Einfach sagen wenn ihr meint.

Code: (dl )
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;
}


Beispiel ist oben ;)

Noch mal danke und wünsche Sie ein frohes neues Jahr!
Alexander\n\n

<!--EDIT|polkana|1167495769-->

View full thread Soll man den hash "resetten" ?: Suche die Lösung für %Hash