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.1, Thu Aug 7 08:33:42 2003 UTC (20 years, 7 months ago) by rajo

Script for parsing output from '/sbin/ifconfig'.

#!/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$

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


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