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.
-rwxr-xr-x 1 root root 59 Jul 29 07:48 grab_ip
Its a chmod 755 file, and contains only the following:
ifconfig eth0 | grep inet | cut -c 21-31
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.
in my case of course... Im the first ip on my home lan
what about "hostname -i" ? ever tried?
* update - tried that , but that returns locahost addr:
[root@dogma root]# hostname -i
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.
strange, this (like any other} workstation on my lan gets the address via dhcp.....
btw, the manpage reads: .......
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 :) )
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 :(
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.