Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate random IPv6 address
#!/bin/sh
# example: ./ramdom-ipv6.sh 2402:f000:1::/48 166.111.21.1
table_id=436298364
ipv6_cidr=$1
ipv4_addr=$2
ipv6_prefix=$(echo $ipv6_cidr | cut -d / -f 1)
ipv6_sublen=$(echo $ipv6_cidr | cut -d / -f 2)
ip -6 route flush table $table_id
ip -6 route add blackhole $ipv6_prefix$ipv4_addr/128 table $table_id
ipv6_addr=$(ip -6 route show table $table_id | cut -d ' ' -f 2 | cut -d / -f 1)
echo $ipv6_addr/$ipv6_sublen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.