nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   NVIDIA Linux (http://www.nvnews.net/vbulletin/forumdisplay.php?f=14)
-   -   quick and easy Ip grabber (http://www.nvnews.net/vbulletin/showthread.php?t=171)

noeffort 07-29-02 11:57 PM

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!

mtrr 07-30-02 05:57 PM

what about "hostname -i" ? ever tried?

cheers

noeffort 08-04-02 09:36 PM

ah, thanks!

* update - tried that , but that returns locahost addr:

[root@dogma root]# hostname -i
127.0.0.1

I am DHCP served by my Netgear FVS-318, so my IP on the subnet is 192.168.0.2

I could set that IP via:

[root@dogma root]# neat &

and change it under hosts, however, then that messes with my locahost dev'ing of PHP projects.

plus, then its not dynamic, id have to change the neat config again if I changed my IP on the LAN.

But thanks still, I KNEW there had to be a one word + -switch command that would yield the IP...

*going to now try w/ neat configured with 192.168.0.2 for kicks.

mtrr 08-06-02 10:34 AM

strange, this (like any other} workstation on my lan gets the address via dhcp.....

btw, the manpage reads: .......


-i, --ip-address
Display the IP address(es) of the host.

.......

tried that with three multihomed machines, always got the address of
the first configured interface (in one case it was eth1 :) )


strange.....

mtrr 08-06-02 11:05 AM

mhm...random thought:

what about customizing "/etc/dhclient-script"?

I just found out _why_ I always got the correct address back :)! good DNS setup.

dig through that script and modify the function that
writes "/etc/resolv.conf" to also write a _new_ "/etc/hosts", not hard at all!

assuming you use dhclient, for pump read the man page :(

logan 08-06-02 05:03 PM

1 Attachment(s)
Or if you wanted to do something in c...

ioctl(int, SIOCGIFADDR, struct ifreq);


All times are GMT -5. The time now is 07:14 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.