<p>On a Linux box, the common interface names look like eth0, eth1, etc. I know how to find at least one IP address using <code>gethostbyname</code> or similar functions, but I don't know any way to specify which named interface I want the IP address of. I could use ifconfig and parse the output, but shelling out for this information seems... inelegant.</p>

<p>Is there a way to, say, enumerate all the interfaces and their IP addresses (and maybe MAC addresses) into a collection? Or at least something along the lines of <code>gethostbyinterface("eth0")</code>?</p>

edit:
I saw you don't like shelling. Then you can look at how ifconfig does its job (it extracts at least some information from /proc).
When you have interface name, you can do this (in your shell):
```
```
ifconfig eth0 | grep 'inet addr' | sed -e 's/:/ /' | awk '{print $3}'
```
```
To enumerate interfaces you can use this:
```
```
ifconfig | egrep '^[^ ]' | awk '{print $1}'
```
```
Combined:
```
```
for x in `ifconfig | egrep '^[^ ]' | awk '{print $1}'`; do
  echo -n "${x}"
  echo -n "    "
  ifconfig "${x}" | grep 'inet addr' | sed -e 's/:/ /' | awk '{print $3}'
done
```
```