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

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

Revízia 1.2, Thu Jan 12 19:02:04 2006 UTC (16 years, 4 months ago) by rajo

Zmeny od 1.1: +4 -1 [lines]

Sync.

#!/usr/bin/awk -v FS="[: \t]+" -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
#
# 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;
    SUBSEP = ":";
}

/^[a-zA-Z0-9:]+[ \t]+/ { # Linux
    iface = $1;
    ipcount[iface]++;
    iface_count++;
}

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

/^[ \t]+inet6 addr:/ { # Linux
    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 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