This question already has an answer here:
Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address.
I am not interest to get localhost address, want to get private IP address.
|
This question already has an answer here: Want to get the IP address using Shell script. Without knowing the eth0 or eth1 or eth2 How to get the particular IP address. I am not interest to get localhost address, want to get private IP address. |
||||
marked as duplicate by jasonwryan, slm, Anthon, rahmu, Timo Mar 12 at 12:37This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
||||
| add comment | ||||
|
You can do :
which gives you the first private IP address listed in For example, with
With the commandline before, I get To put it in a variable inside a shell script, you can do |
|||||||||||||||||
|
|
If you want list all ip address, regardless its name, try this:
or:
|
|||||||||
|
|
Flagrant copy paste from stackoverflow since we can't dupe across sites. I know it's not bash or sh, but who doesn't have python installed at this point anyway? You should use netifaces. It is designed to be cross-platform on Mac OS X, Linux, and Windows.
The numbers used to index protocols are from
End copy paste If all you want is the IP of the up and outbound interface, this works. Yet ANOTHER option if you just want to enumerate over up interfaces, since nobody seems to be able to understand exactly what you want:
|
|||||||||||||||||||||
|
ifconfig -awhat you're looking for? – rusty Mar 12 at 7:43ifconfig -a. In fact the answer you marked as accepted does just that (just usesipinstead ofifconfig). – Patrick Mar 12 at 12:47