Re: get MAC Address from IP

From: John Saunders (johnwsaundersiii)
Date: 11/11/04


Date: Thu, 11 Nov 2004 09:46:05 -0500


"Gareth Watson" <gw-ext@abs-ltd.com> wrote in message
news:eOPwys0xEHA.4028@TK2MSFTNGP15.phx.gbl...
>
> "John Saunders" <johnwsaundersiii at hotmail.com> wrote in message
> news:%238LW%23gUxEHA.3976@TK2MSFTNGP09.phx.gbl...
>> "YAN" <YAN@discussions.microsoft.com> wrote in message
>> news:9586DF60-A3BF-4C58-B94B-B59B7535F775@microsoft.com...
>>> Hi,
>>> I want to get the mac address from a machine, which i have the IP
>>> address of
>>> that machine, how can i do that?
>>
>> You can't. There's no relationship between the two.
>>
>> And besides, a machine may have multiple IP addresses and multiple MAC
>> addresses.
>>
>> John Saunders
>>
>>
>
> No relationship between MAC address and IP address? Did I read that
> right! Of course there's a relationship how else would you move from layer
> 3 (IP) to layer 2 (MAC).
>
> In fact there is a whole protocol for this conversion. Its called ARP.
>
> Basically ARP broadcasts on the segment asking all the devices to repond
> with their MAC if they own the stated IP. This is a simplification of the
> process but it is basically what happens.
>
> I have no idea how to do this in .Net but saying there is no relationship
> is clearly not the case.

Do this thought experiment.

1) ARP for the MAC address associated with a given IP address (*). Call the
result "m".
2) Now, once again ARP for the MAC address, calling the result "m'".

Question: under what circumstances will m = m'?

If your code lives in a world where those circumstances will always apply,
then for your code, there is a relationship between IP address and MAC
address. But in general, m may not be the same as m', which means that, in
general, there is no useful relationship between IP address and MAC address.

Also, IN GENERAL, it's a bad idea for code which is not running the network
to screw with network "stuff" like IP addresses (also routes, etc). If the
code isn't running the network, then it has no idea when the network will
decide to pull the assumptions out from under its feet.

As an example, consider code that treats the IP address as the identity of a
machine. That code will be disappointed when the machine loses its DHCP
lease and starts using a different IP address. Strangely, DHCP didn't bother
telling the code that the network had decided to change implementation
specifics. Note that the network layer won't be troubled by this change, but
this hypothetical code _will_ be.

This rant is probably just a sign that I'm getting old, but you might want
to consider the different layers of a network like different classes in an
OO design. Class "EndApplication" shouldn't be using nor depending on
private members of class "Network". In fact, there's some reason to doubt
that class "EndApplication" should even know of the existance of class
"Network".

John Saunders

(*) I presume you realize that ARP is not a routed protocol? You can't use
it at all for a machine not on the same logical network segment. Even on the
same logical segment, you may not be able to use it on all hosts, as
something at the Network/Datalink layer may block ARP traffic.



Relevant Pages

  • TidBITS#794/29-Aug-05
    ... This week's issue brings a potpourri of Mac news, ... Mark Anbinder looks briefly at Google Talk, ... Adding Tiger's AirPort Preferred Network List ...
    (comp.sys.mac.digest)
  • Re: MAC address spoofing - conflict?
    ... That being the case I would think that all network cards on that collision domain would get the packet. ... ARP broadcasts and the question is what will happen. ... ARP asks for an _IP_ address, not a MAC one. ... Cenzic Hailstorm finds vulnerabilities fast. ...
    (Pen-Test)
  • Re: Leopard Sidebar Question
    ... (But if you've rebooted your Mac that will clear the arp table. ... it's handy for cases like Apple which have their own network interface devices. ... For example the internal interface for my firewall box, a soerkris 4801, give me "SiByte, Inc" which doesn't really help that much, on the other hand the MAC for my Wii does return Nintendo. ... the situation is rather surprising. ...
    (comp.sys.mac.system)
  • Re: scan for machines in the subnet
    ... still respond to an ARP packet addressed to it's IP address. ... A switch on a meshed network can reply to ARP with it's own MAC. ... They don't change often, fortunately - but I'm reconfiguring things at the moment, and that means each manually configured server, workstation and printer must be changed. ...
    (comp.os.linux.networking)
  • Apples new software may steal the show
    ... Steve Jobs, Apple Computer's co-founder and performer in chief, rarely shows any reluctance to sell -- or even over-sell -- his company's accomplishments. ... Jobs spent only about five minutes talking about what I see as the big news of the day: Apple's first software for using a home network through a television screen rather than a computer monitor. ... Apple's Mac OS X, the software running all its Macintosh computers, also has built-in features for easily connecting Macs in a network. ...
    (comp.sys.mac.advocacy)