After a brief glance at your code, I'd say the echo is to blame. If you don't need it, remove it. Or, you can do as DGPickett suggests and not quote the $IP.
I did not get this:
where are you asking for the association between an a-priori known MAC address and the IP address assigned from the DHCP?
The scenario:
I'm on machine A with all networking data up and running.
I know that on my subnet there's a machine B whose MAC address is given.
As soon as B is booted-up it takes an IP from the DHCP server on the network and I want to know it.
I'd really be interested in more subtle and keen ways of doing this wrt what I posted in the thread opening.
Well, the arp cache is a great way to see who is out there, so if other methods fail, just ping the broadcast so all hosts echo back and it fills the cache. You may get bridge MACs for more remote hosts.
If DHCP or configuration has not given your host an IP, or you do not have PATH MTU, the UH will be missing. Even my windows PC shows its IP on netstat -rn, because the NIC is gateway to the collision domain hosts. You can get it from a U record, too:
I never have DHCP assigned IPs. My ISP uses DHCP to assign my router a real IP, but inside the premises I am lord almighty of the network.
You're right about loopback though. I didn't notice that before. I'll have to check into that.
---------- Post updated at 07:26 PM ---------- Previous update was at 06:57 PM ----------
I think I remember loop addresses previously being included in the output of netstat -nr, but I just checked, and it's not included in any of the 4 Linux boxes I have running right now (2 Fedora, 1 Ubuntu and 1 Arch). Yet I can ping and ssh to localhost on each.
I must not have been paying attention when it became implicit on Linux.
Windows has routing to push all local IPs to loopback, so I guess this is a step in the other direction. The IP stack can deal with loopback and hide it from routing. On Solaris and HP-UX I always see it. Well, not the most portable thing. Even ping output varies a lot. It's a shame they cannot get their act together on one set of network commands and facilities, consistent presentations! I was not amused when they overloaded the routing table with path MTU. At least HP seems to does it with less clutter than I recall on Solaris.