Created
September 11, 2018 01:52
-
-
Save gaoyifan/7b8ccc9f299335f54d5ea0875d197136 to your computer and use it in GitHub Desktop.
Generate random IPv6 address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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