Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a remote MAC address via IPv6 in iOS programmatically

Tags:

I need to find a solution how to get the MAC address from the other device in the WiFi network. There is a good method how to do this for IPv4 (How does iOS app Fing get MAC Address?), but how to do this for IPv6? Since ARP was replaced by the NDP (Neighbour Discovery Protocol), the latter method doesn't work. I would greatly appreciate if anyone could help me.

like image 257
Max Niagolov Avatar asked Jul 10 '16 04:07

Max Niagolov


People also ask

Does IPv6 contain MAC address?

The IPv6 EUI-64 format address is obtained through the 48-bit MAC address. The MAC address is first separated into two 24-bits, with one being OUI (Organizationally Unique Identifier) and the other being NIC specific. The 16-bit 0xFFFE is then inserted between these two 24-bits for the 64-bit EUI address.

Which protocol is available to IPv6 addresses to MAC addresses?

Address Resolution Protocol (ARP) is a procedure for mapping a dynamic IP address to a permanent physical machine address in a local area network (LAN). The physical machine address is also known as a media access control (MAC) address.


2 Answers

Layer and Encapsulation

The network architecture is layered, the upper layer encapsulate the different implementations of lower layer and provide higher abstraction relative to lower layer. The network layer which use IP encapsulate different link layers protocols, like Ethernet, WiFi, PPP (which may run on serial cable which not use MAC address) etc.

  • So, the first problem is what do you mean by remote?

If you mean other hosts in WAN, it is impossible unless both device implement a specific protocol: you send a request to those device, they reply with his mac address.

If you mean other host in the same LAN, you can use ARP protocol in IPv4 and NDP (which ) in IPv6.

Arp & NDP

ARP send broadcast in LAN when it knows the IP address of a host but not MAC address, then the hosts which find someone is calling for him reply its MAC address.

NDP provides two main part of functionality, the first is the same with ARP: mapping between network- and link-layer addresses. (The difference is NDP using a multicast address: prefix f02::1:f/104, combined with the low-order 24 bits of the solicited IPv6 address)

So what you need is to send ICMPv6 Neighbor Solicitation message.

Address Assignment in IPv6

Link-local IPv6 addresses (and some global IPv6 addresses) use interface identifiers (IIDs) as a basis for unicast IPv6 address assignment. ... IIDs are ordinarily 64 bits long and are formed either directly from the underlyinglink-layer MAC address of a network interface using a modified EUI-64 format. or by another process that randomizes the value in hopes of providing some degree of privacy against address tracking.

So in the most common cases, you can get the MAC address of a device directly from their IPv6 link local address.

Conclusion:

  • implement your protocol in both devices
  • send NDP message to solicited node if it is in same LAN
  • extract MAC address from link local IPv6 address

Ref

  • Wikipedia
  • TCP/IP Illustrated, volume 1
like image 149
Tony Avatar answered Sep 20 '22 08:09

Tony


I'm using MMLanScan for that purpose. It's very simple to get working to find IP/MAC addresses of devices on your LAN.

I use it some time ago but I think it's works with IPv6 also.

like image 23
sergiog90 Avatar answered Sep 20 '22 08:09

sergiog90