Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Piatok, 19. apríl 2024

Rozdiely pre scripts/shell/firewall/ifconfig-parse.pl medzi verziami 2.1 a 2.2

verzia 2.1, 2007/08/29 14:43:55 verzia 2.2, 2015/10/12 22:41:24
Riadok 1 
Riadok 1 
 #!/usr/bin/perl -w  #!/usr/bin/perl -w
   
   use strict;
   use warnings;
   
 #  #
 # ifconfig-parse.pl - parse output from ifconfig and print  # ifconfig-parse.pl - parse output from ifconfig and print
 #                      in format suitable for eval in shell  #                      in format suitable for eval in shell
Riadok 13 
Riadok 16 
 # 2007-08-29 - created  # 2007-08-29 - created
 #  #
   
 # $Platon: $  # $Platon: scripts/shell/firewall/ifconfig-parse.pl,v 2.1 2007-08-29 14:43:55 rajo Exp $
   
 #use Data::Dumper;  #use Data::Dumper;
   
 my $iface_count = 0;  my $iface_count = 0;
 my $iface;  my $iface;
 my (%ip6, %scope6, %bcast, %mask, %hwaddr, %ipcount);  my (%ip, %ifname, %ip6, %scope6, %bcast, %mask, %hwaddr, %ipcount);
   
 while (my $line = <STDIN>) {  while (my $line = <STDIN>) {
         chomp $line;          chomp $line;
         if ($line =~ m/^([a-z0-9:]+)\s+.*?([a-z0-9:]+)\s*$/i) { # Linux interface          if ($line =~ m/^([a-z0-9:]+)\s+.*?([a-z0-9:]+)\s*$/i) { # Linux interface
                 $iface  = $1;                  $iface  = $1;
                 my $iface_hwaddr = $2;                  my $iface_hwaddr = $2;
                 $iface  = [ $iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"                  my $x_iface     = $iface;
                   $iface  =~ s/:$//g;
                   $iface  =~ s/:/_/g; # convert "eth0:0" --> "eth0_0"
                   $x_iface                = [ $x_iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"
                   $ifname{$iface} = $x_iface;
                 $ipcount{$iface}++;                  $ipcount{$iface}++;
                 $hwaddr{$iface} = $iface_hwaddr;                  $hwaddr{$iface} = $iface_hwaddr;
                 $iface_count++;                  $iface_count++;
Riadok 44  while (my $line = <STDIN>) {
Riadok 51  while (my $line = <STDIN>) {
                 push @{$ip6{$iface}}, $fields[3];                  push @{$ip6{$iface}}, $fields[3];
                 $scope6{$iface} = [ $fields[4] =~ m/Scope:(.*)$/i ]->[0];                  $scope6{$iface} = [ $fields[4] =~ m/Scope:(.*)$/i ]->[0];
         }          }
           elsif ($line =~ m/^[ \t]+inet\s/) { # Linux IP address
                   die unless defined $iface;
                   my @fields = split(/[\s:]+/, $line);
                   push @{$ip{$iface}}, $fields[2];
                   $bcast{$iface} = (defined($fields[5]) and $fields[5] eq "broadcast") ? $fields[6] : "";
                   $mask{$iface} = $fields[4];
           }
   
 }  }
   
 map { printf "IP_%s=\"%s\";                     export IP_%s;\n",               $_, join(" ", @{$ip{$_}}),      $_; } keys %ip;  map { printf "IP_%s=\"%s\";                     export IP_%s;\n",               $_, join(" ", @{$ip{$_}}),      $_; } keys %ip;
Riadok 54  map { printf "Bcast_%s=\"%s\";        export B
Riadok 68  map { printf "Bcast_%s=\"%s\";        export B
 map { printf "Mask_%s=\"%s\";           export Mask_%s;\n",             $_, $mask{$_},  $_; } keys %mask;  map { printf "Mask_%s=\"%s\";           export Mask_%s;\n",             $_, $mask{$_},  $_; } keys %mask;
 map { printf "HWaddr_%s=\"%s\";         export HWaddr_%s;\n",   $_, $hwaddr{$_},        $_; } keys %hwaddr;  map { printf "HWaddr_%s=\"%s\";         export HWaddr_%s;\n",   $_, $hwaddr{$_},        $_; } keys %hwaddr;
 map { printf "IPcount_%s=\"%s\";        export IPcount_%s;\n",  $_, $ipcount{$_},       $_; } keys %ipcount;  map { printf "IPcount_%s=\"%s\";        export IPcount_%s;\n",  $_, $ipcount{$_},       $_; } keys %ipcount;
 printf "interfaces=\"%s\";      export interfaces;\n", join(" ", keys %ip);  map { printf "IFname_%s=\"%s\";         export IFname_%s;\n",   $_, $ifname{$_},        $_; } keys %ifname;
   printf "interfaces=\"%s\";      export interfaces;\n", join(" ", sort keys %ip);
   

Legend:
Odstranené z verzie2.1  
zmenené riadky
  Pridané vo verzii2.2

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok