View Single Post
Old 07-30-02, 12:57 AM   #1
noeffort
Guest
 
Posts: n/a
Default quick and easy Ip grabber

I am SURE there is an easier way, ie, a one word program to type at command line to just echo back your IP address,.. but just in case there isn't...

I was bored at work, and created a sh script that creates an HTML header and sets base address to the local machines ip rather than the usual localhost/index.html

So, I could not for the life of me remember or find if there is an "IP" command to just grab the ip. Our head sys ad could not remember and he's like a walking man page.

Hence:

-rwxr-xr-x 1 root root 59 Jul 29 07:48 grab_ip

aka grab_ip

Its a chmod 755 file, and contains only the following:

ifconfig eth0 | grep inet | cut -c 21-31


That's it.

the output of ifconfig eth0 gives white space in front of the number, and that's why cut begins at character 21

Change eth0 to your physical link ad hoc and there you go.

Output:
192.168.0.2

in my case of course... Im the first ip on my home lan

Have fun!
  Reply With Quote