Skip to content

Instantly share code, notes, and snippets.

@gaoyifan
Created September 11, 2018 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaoyifan/7b8ccc9f299335f54d5ea0875d197136 to your computer and use it in GitHub Desktop.
Save gaoyifan/7b8ccc9f299335f54d5ea0875d197136 to your computer and use it in GitHub Desktop.
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