Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Get IPv6 address from IPv4? [closed]

Writer Mia Lopez

Is it possible to do this? I don't care what tool, ping, nmap, nslookup. Hell, i'll even write a bash script. I just need to figure this out.

Edit: All I know are IPv4 addresses and I want to see what their IPv6 addresses are. I realistically cannot scan a whole /32 block of IPv6 and that's terribly inefficient anyways. TL;DR

IPv4 Input > IPv6 Output

Pseudo-code:

ping 1.2.3.4

Result:

1.2.3.4: IPv6 Address

7

1 Answer

There is no direct mapping between IPv4 and IPv6 addresses. The most reliable way I can think of (which requires you to be on the same network as the IPv4 node) is to get the MAC address for the IP, and construct a link-local EUI-64-based address from it. That is, IPv6 nodes will almost always automatically configure a MAC-based link-local address, so this should work in most cases.

The following quick-and-dirty example script works on Ubuntu Xenial (16.04) as long as the python3-netaddr package is installed. It doesn't seem to work on Trusty (14.04) since the netaddr library is missing some of the required functionality.

#!/bin/bash -e
IP=$1
ping -c 1 $1 > /dev/null 2> /dev/null
MAC=$(arp -an $1 | awk '{ print $4 }')
IFACE=$(arp -an $1 | awk '{ print $7 }')
python3 -c "
from netaddr import IPAddress
from netaddr.eui import EUI
mac = EUI(\"$MAC\")
ip = mac.ipv6(IPAddress('fe80::'))
print('{ip}%{iface}'.format(ip=ip, iface=\"$IFACE\"))"

Example usage (assuming you pasted the contents into ipv4-to-ipv6.sh and did a chmod +x ipv4-to-ipv6.sh):

./ipv4-to-ipv6.sh 192.168.0.1
fe80::224:b4ff:fe9c:1329%eth0

Note that this is a link-local address must be scoped to a particular link in order to be useful, so requires the %<interface> to be usable in most application. If your hosts have a global unicast prefix on this network as well, they would be probably be reachable using the MAC-based address there, too. (you could, for example, change the ip = mac.ipv6(...) line to use your global prefix, and that should work.)

5