Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP Address into Variable 1

Status
Not open for further replies.

jestrada101

Technical User
Mar 28, 2003
332
Hello,
Can someone tell me how to get the local machines IP address into a variable? Using a Korn.

Thanks
je
 
Try something like this:|code]
myIP=$(awk "/[ \t]+$(hostname)/"'{print $1}' /etc/hosts)[/code]

Hope This Help
PH.
 
If you have a dynamic IP Address that isn't in your /etc/hosts, try that :

myIP=`/sbin/ifconfig eth1 | grep addr: | awk '{print $2}' | awk -F : '{print $2}'`

It could certainly be ameliorated, but it works fine

Hope this help

AlexRezid
 
The output of the ifconfig command, if it is implemented, is highly dependent of the *nix flavor.

Hope This Help
PH.
 
# Solaris
thisHost=$(/usr/sbin/arp $(hostname) | nawk -F'[()]' '{print $2}')

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top