Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 27. september 2022

Súbor: [Platon] / scripts / shell / firewall / ifconfig-parse.awk (stiahnutie)

Revízia 1.4, Thu Jan 12 19:28:46 2006 UTC (16 years, 8 months ago) by rajo


Zmeny od 1.3: +10 -7 [lines]

Parse also MAC address (HWaddr_eth0 etc.)

#!/usr/bin/awk -f

#
# ifconfig-parse.awk - parse output from ifconfig and print
#                      in format suitable for eval in shell
#
# Only Linux is supported, but *MULTIPLE* IP address per device.
#
# If you need parse ifconfig output on FreeBSD, use ifconfig-parse.sh
# script instead.
#
# Developed by Lubommir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2006 Platon SDG
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2006-01-12 - created
#

# $Platon: scripts/shell/firewall/ifconfig-parse.awk,v 1.3 2005/03/04 23:54:05 rajo Exp $

BEGIN {
    iface_count = 0;
}

/^[a-zA-Z0-9:]+[ \t]+/ { # Linux interface
    split($1, fields, ":");
    iface = fields[1];
    ipcount[iface]++;
    hwaddr[iface] = $NF;
    iface_count++;
}

/^[ \t]+inet addr:/ { # Linux IP address
    split($0, fields, "[ \t:]+");
    ip[iface, ipcount[iface]] = fields[4];
    bcast[iface] = fields[6]; # bad for loopback interface, but we don't need this
    idx = length(fields);
    mask[iface] = fields[idx];
}

/^[ \t]+inet6 addr:/ { # Linux IPv6 address
    split($0, fields, "[ \t]+");
    ip6[iface] = fields[4];
    scope6[iface] = fields[5];
}

END {
    for (i in ip6)        { printf "IFACE_6_%s=\"%s\";    export IFACE_6_%s;\n",    i, ip6[i],        i; }
    for (i in scope6)    { printf "SCOPE_6_%s=\"%s\";    export SCOPE_6_%s;\n",    i, scope6[i],    i; }
    for (i in bcast)    { printf "Bcast_%s=\"%s\";        export Bcast_%s;\n",    i, bcast[i],    i; }
    for (i in mask)        { printf "Mask_%s=\"%s\";        export Mask_%s;\n",        i, mask[i],        i; }
    for (i in hwaddr)    { printf "HWaddr_%s=\"%s\";        export HWaddr_%s;\n",    i, hwaddr[i],    i; }
    for (i in ipcount)    { printf "IPcount_%s=\"%s\";    export IPcount_%s;\n",    i, ipcount[i],    i; }
    for (i in ipcount) {
        printf "IP_%s=\"", i;
        for (n = 1; n <= ipcount[i]; n++) {
            printf "%s ", ip[i, n];
        }
        printf "\";    export IP_%s;\n", i;
    }
    printf "interfaces=\"";
    for (i in ipcount) { printf "%s ", i; }
    printf "\";     export interfaces;\n";
}


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