#!/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' # Copyright (c) 2006 Platon SDG # Licensed under terms of GNU General Public License. # All rights reserved. # # $Platon: scripts/shell/firewall/ifconfig-parse.sh,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"; }