Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a remote MAC address via IPv6

Is it possible to get the MAC from an another PC in the same Network via IPv6 (without WMI)? With IPv4 it is easy (ARP).

IPv6 uses the "Neighbor Discovery Protocol" (NDP) to get the MAC address. Are there any methods in .Net for this?

like image 248
Fabian Avatar asked Oct 13 '22 21:10

Fabian


2 Answers

You can run the external command "netsh int ipv6 show neigh", and filter out the host you are interested in. You should have contacted it just before that, so you know it is in the NC.

If you want an API for that, use GetIpNetTable2 or, more directly, ResolveIpNetEntry2. I doubt there is a .NET API for this, so you'll have to use PInvoke.

like image 108
Martin v. Löwis Avatar answered Oct 27 '22 10:10

Martin v. Löwis


Martin's answer was for Windows, but this is for if you are on a GNU/Linux or other *nix box.

You want to use the neigh function of the ip command to show IPv6 neighbours, like so:

$ ip -6 neigh
fe80::200:ff:fe00:0 dev eth0 lladdr 00:0e:54:24:23:21 router REACHABLE
fe80::202:b0ff:fe01:2abe dev eth0 lladdr 00:02:b0:02:2a:be DELAY

(Pro tip: you can leave the -6 off and view IPv4 ARP as well as IPv6 ND in the same list.)

Also, if you want to find out the MAC addresses of all the IPv6 machines on the LAN, and not just those you already know about, you should ping them first, then look for neighbours:

$ ping6 ff02::1%eth0
64 bytes from fe80::221:84ff:fe42:86ef: icmp_seq=1 ttl=64 time=0.053 ms # <-- you
64 bytes from fe80::200:ff:fe00:0: icmp_seq=1 ttl=64 time=2.37 ms (DUP!)
64 bytes from fe80::202:b0ff:fe01:2abe: icmp_seq=1 ttl=64 time=2.38 ms (DUP!)
64 bytes from fe80::215:abff:fe63:f6fa: icmp_seq=1 ttl=64 time=2.66 ms (DUP!)

$ ip -6 neigh
fe80::200:ff:fe00:0 dev eth0 lladdr 00:0e:54:24:23:21 router REACHABLE
fe80::202:b0ff:fe01:2abe dev eth0 lladdr 00:02:b0:02:2a:be DELAY
fe80::215:abff:fe63:f6fa dev eth0 lladdr 00:02:15:ab:f6:fa DELAY # <-- a new one!
like image 39
Jeremy Visser Avatar answered Oct 27 '22 10:10

Jeremy Visser