[ale] finding ip address of host

Keith Ledford ktledford at mindspring.com
Mon Sep 17 21:30:51 EDT 2001


Hello all,

I am helping a co-worker write some generic ipchains rules. We are trying to
come up with a file that is really generic and uses variables. This is not a
problem for the most part. I need to find out the ip address of the host. I
have a series of commands that will do it. Anyone have a better way? This
will be running on a Suse 7.0 box. 

ifconfig eth0 |grep -i inet | cut -f2 -d":" |cut -f1 -d" "

I need to keep it to basic UNIX commands (no Perl) and /bin/sh script.

Breakdown of command:

Output of ifconfig eth0 is 
eth0      Link encap:Ethernet  HWaddr XX:XX:XX:XX:XX:XX  
          inet addr:1.2.3.4  Bcast:255.255.255.255 Mask:255.255.255.0
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:10924 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7673 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          Interrupt:3 Base address:0x300

grep -i inet gets the line
inet addr:1.2.3.4  Bcast:255.255.255.255 Mask:255.255.255.0

cut -f2 -d":" gets
1.2.3.4  Bcast

cut -f1 -d" " gets
1.2.3.4


Thanks!

-- 
Keith Ledford
email: ktledford at mindspring.com
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list