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

File: [Platon] / scripts / shell / firewall / ifconfig-parse.sh (download)

Revision 1.2, Fri Aug 8 09:56:53 2003 UTC (20 years, 7 months ago) by rajo

Changes since 1.1: +23 -10 lines

Support both GNU/Linux and FreeBSD version of ifconfig output.

#!/bin/sh

#
# ifconfig-parse.sh - parse output from ifconfig and print
#                     in format suitable for eval in shell
#
# Developed by Lubommir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2003 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#

# $Platon: scripts/shell/firewall/ifconfig-parse.sh,v 1.1 2003/08/07 08:33:42 rajo Exp $

# Parse output from ifconfig:
/sbin/ifconfig | \
    awk 'BEGIN { interfaces=""; }
        /^[a-zA-Z0-9]+[ \t]+/ { # Linux
            iface=$1;
            interfaces = sprintf("%s %s", interfaces, iface);
            printf "\nIFACE_%s=\"%s\";    export IFACE_%s;\n", iface, iface, iface;
            printf "HWaddr_%s=\"%s\";    export HWaddr_%s;\n", iface, $5, iface;
        }
        /^[ \t]+inet addr:/ { # Linux
            split($0, fields, "[ \t:]+");
            printf "IP_%s=\"%s\";    export IP_%s;\n", iface, fields[4], iface;
            printf "Bcast_%s=\"%s\";    export Bcast_%s;\n", iface, fields[6], iface;
            printf "Mask_%s=\"%s\";    export Mask_%s;\n", iface, fields[8],  iface;
        }
        /^[a-zA-Z0-9]+:/ { # FreeBSD
            iface = $1;
            sub(":", "", iface);
            interfaces = sprintf("%s %s", interfaces, iface);
            printf "\nIFACE_%s=\"%s\";    export IFACE_%s;\n", iface, iface, iface;
        }
        /^[ \t]+inet [0-9]+/ { # FreeBSD
            printf "IP_%s=\"%s\";    export IP_%s;\n", iface, $2, iface;
            printf "Bcast_%s=\"%s\";    export Bcast_%s;\n", iface, $6, iface;
            printf "Mask_%s=\"%s\";    export Mask_%s;\n", iface, $4,  iface;
        }
        /^[ \t]+ether/ { # FreeBSD
            printf "HWaddr_%s=\"%s\";    export HWaddr_%s;\n", iface, $2, iface;
        }
        END { printf "\ninterfaces=\"%s\";     export interfaces;\n", interfaces; }
    '


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