in reply to Re: How do I get the local internet IP address?
in thread How do I get the local internet IP address?

Hi all, thanks for your feedback. I also thought that LC_ALL is the 'right' way to do it because it has precedence over LANG, but when I tested it yesterday, only LANG did work. That's because LANG is automatically exported, LC_ALL not (on the machines available to me). So leaving the semicolon away made LC_ALL=C work. I'll update that, after testing it with the Solaris boxes.
Actually, the regular expressions are so fuzzy, they match any language that is available on my installation (cs, de, et_EE, fr, pt_BR - the other 129 languages have no localisation for ifconfig (net-tools here)). Right this approach is not perfect, but I thought the phrases 'Sample' and 'last resort' made clear, that this is not production code and one might need to fiddle a bit around with it? Would you suggest to make that more explicit?

The reason why I presented this sample was because it works for me and it shows another approach (TIMTOWTDI) that amend to the already given answers. If it works it works without the need to establish a connection and it lists all IPs, not only the one that leaves the (usually "default") route as when contacting a root name-server. This is handy if you're behind several layers of firewalls and in situations where you are interested in the local IP configuration.
If the intention of the question is more like How do I get the local internet IP address that currently connects my host to the IP a.b.c.d? (which is often not identical with the IP address other hosts would contact the local machine in return), then I would prefer this suggestion from tirwhan. Also because it doesn't require to install a non standard module beforehand.

Any other advice is appreciated. Thanks again.

  • Comment on Re: Answer: How do I get the local internet IP address?