Skip to contentSkip to conversation

Getting info from ifconfig output

DISCUSSION Bill Davidsen 1 participant 1 message Mar 12, 2003

lore
Share & tools
lore
#0 lore raw

Browsing the list I saw a question regarding using grep and friends to get an IP. I do this, but to allow a single firewall config file to be used on a number of machines without editing. Here are the first few lines, I hope they are useful to someone. I extract the IP and the broadcast (I don't always have 8 bit subnetting).

# define internal and external interfaces
int_i=eth0
ext_i=eth1
loopback=lo
# define the IP of the external address, only IP used
AdrsLine=$(ifconfig ${ext_i} | grep "inet addr:")
ext_ip=$(expr "$AdrsLine" : ".*inet addr: *\([0-9.]*\)")
Bcast=$(expr "$AdrsLine" : ".*Bcast: *\([0-9.]*\)")
Signature · 2 lines
bill davidsen ([email protected])
Doing interesting things with small computers since 1979.