Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, April 18, 2024

Diff for scripts/shell/firewall/ifconfig-parse.sh between version 1.2 and 1.3

version 1.2, 2003/08/08 09:56:53 version 1.3, 2005/03/04 23:54:05
Line 4 
Line 4 
 # ifconfig-parse.sh - parse output from ifconfig and print  # ifconfig-parse.sh - parse output from ifconfig and print
 #                     in format suitable for eval in shell  #                     in format suitable for eval in shell
 #  #
   # FreeBSD and Linux are supported
   #
 # Developed by Lubommir Host 'rajo' <rajo AT platon.sk>  # Developed by Lubommir Host 'rajo' <rajo AT platon.sk>
 # Copyright (c) 2003 Platon SDG  # Copyright (c) 2003 Platon SDG
 # Licensed under terms of GNU General Public License.  # Licensed under terms of GNU General Public License.
 # All rights reserved.  # All rights reserved.
 #  #
   
 # $Platon: scripts/shell/firewall/ifconfig-parse.sh,v 1.1 2003/08/07 08:33:42 rajo Exp $  # $Platon: scripts/shell/firewall/ifconfig-parse.sh,v 1.2 2003/08/08 09:56:53 rajo Exp $
   
   PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
   export PATH
   
 # Parse output from ifconfig:  # Parse output from ifconfig:
 /sbin/ifconfig | \  ifconfig | \
         awk 'BEGIN { interfaces=""; }          awk 'BEGIN { interfaces=""; }
                 /^[a-zA-Z0-9]+[ \t]+/ { # Linux                  /^[a-zA-Z0-9]+[ \t]+/ { # Linux
                         iface=$1;                          iface=$1;
Line 44 
Line 49 
                 END { printf "\ninterfaces=\"%s\";      export interfaces;\n", interfaces; }                  END { printf "\ninterfaces=\"%s\";      export interfaces;\n", interfaces; }
         '          '
   
   #
   # parse routing info on Linux (FreeBSD not supported yet)
   #
   # only "Gateway Destination Flags MTU Metric Window IRTT" columns are extracted from /proc/net/route:
   if [ "x`uname -s`" = "xLinux" ]; then
   
           perl -e '
           $\ = "\n";
           open(FILE, "/proc/net/route") or die "Cannot open /proc/net/route: $!";
           my @columns = split(/\s+/, <FILE>);
           while (my $line = <FILE>) {
                   my $iface;
                   my @vals = split(/\s+/, $line);
                   foreach my $key (@columns) {
                           $iface->{$key} = shift @vals;
                   }
   
                   foreach my $key (qw( Gateway Destination )) {
                           print "${key}_$iface->{Iface}=",
                                   qw("), hex2ip($iface->{$key}), qw("),
                                   "; export ${key}_$iface->{Iface};";
                   }
                   foreach my $key (qw( Flags MTU Metric Window IRTT )) {
                           print "${key}_$iface->{Iface}=",
                                   qw("), $iface->{$key}, qw("),
                                   "; export ${key}_$iface->{Iface};";
                   }
           }
           close(FILE);
   
   
           sub hex2ip
           { # {{{
                   my ($str) = @_;
                   my @block;
   
                   my $hex = uc($str);
   
                   while (length($hex)) {
                           my $x = ord(substr($hex, 0, 1));
                           my $y = ord(substr($hex, 1, 1));
   
                           $x = $x > 64 ? $x - 55 : $x - 48;
                           $y = $y > 64 ? $y - 55 : $y - 48;
   
                           push @block, 16 * $x + $y;
                           $hex = substr($hex, 2);
                   }
   
                   return join(".", reverse @block);
   
           } # }}}
           '
   
   fi
   
   # vim: ft=sh fdm=marker fdl=0 fdc=3
   

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top