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