Go Back   nV News Forums > Linux Support Forums > NVIDIA Linux

Newegg Daily Deals

Reply
 
Thread Tools
Old 07-29-02, 11:57 PM   #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
Old 07-30-02, 05:57 PM   #2
mtrr
Registered User
 
Join Date: Jul 2002
Location: Germany
Posts: 234
Send a message via ICQ to mtrr
Default

what about "hostname -i" ? ever tried?

cheers
mtrr is offline   Reply With Quote
Old 08-04-02, 09:36 PM   #3
noeffort
Guest
 
Posts: n/a
Default

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.
  Reply With Quote
Old 08-06-02, 10:34 AM   #4
mtrr
Registered User
 
Join Date: Jul 2002
Location: Germany
Posts: 234
Send a message via ICQ to mtrr
Default

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 is offline   Reply With Quote
Old 08-06-02, 11:05 AM   #5
mtrr
Registered User
 
Join Date: Jul 2002
Location: Germany
Posts: 234
Send a message via ICQ to mtrr
Default

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
mtrr is offline   Reply With Quote
Old 08-06-02, 05:03 PM   #6
logan
Registered User
 
Join Date: Aug 2002
Posts: 492
Default

Or if you wanted to do something in c...

ioctl(int, SIOCGIFADDR, struct ifreq);
Attached Files
File Type: txt get_interface_address.c.txt (943 Bytes, 297 views)
logan is offline   Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:20 AM.


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