IP Address command

I am looking for a command that will give me the IP address of the particular machie that I am on.  (Something like the hostname command)
hawhiteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chris_calabreseCommented:
The first problem here is that not all machines have an IP address.  The second is that not all machines have only one IP address.

Meanwhile, the following ought to work on most Unix systems...

nslookup `hostname` | awk '
  /^Name:/ { flag=1 }
  flag && /^Address/ {
    gsub( /,/, "")
    for(i=2; i <= NF; i++)
      print $i
  }'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bkesarlaCommented:
ping -s <hostname> shud fetch you the ip address of the machine..
0
chris_calabreseCommented:
This will fetch an IP address of the machine, but will not fetch all IP addresses if there are more than one.  Of course, this may be good enough in some circumstances.  Meanwhile, you'll also want to make sure you have the right ping options for your particular platform.  For example, on HP-UX, you'd use

/usr/sbin/ping -s 1 -c 1 `hostname` | head -1 | cut -d '(' -f 2 | cut -d ')' -f 1
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

filiepCommented:
Try ifconfig -a
This should give the IP addresses for each NIC thats in the server
0
chris_calabreseCommented:
Again, this depends on the Unix flavor.  On HP-UX, which does not have ifconfig -a, you'd need to do

lanscan | grep '^[0-9]' | awk '{print $5}' | while read dev
do      ifconfig "$dev"
done | grep inet | awk '{print $2}'
0
tspfwjCommented:
ifconfig -a is good to show the addresses, you can also try netstat -in to show the active interfaces and addresses assigned to them
0
chris_calabreseCommented:
Ah, hadn't tought of the netstat -in one.  Yes, that would work too.
  netstat -in | awk '$4 ~ /^[0-9]/ && $4 !~ /^127/ { print $4 }'

I don't know of any OS specific tweaking you'd need, but netstat, and it gives you all the IP's, so that makes it one of the better methods.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.