Last active
March 16, 2020 17:31
-
-
Save lsowen/4447d916fd19cbb7fce4 to your computer and use it in GitHub Desktop.
Calculate Reverse ipv6 PTR Record in Bash (using awk and sed)
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
function reverseIp6 { | |
echo "$1" | awk -F: 'BEGIN {OFS=""; }{addCount = 9 - NF; for(i=1; i<=NF;i++){if(length($i) == 0){ for(j=1;j<=addCount;j++){$i = ($i "0000");} } else { $i = substr(("0000" $i), length($i)+5-4);}}; print}' | rev | sed -e "s/./&./g" | |
} | |
$(reverseIp6 "2001:db8:85a3::8a2e:370:7334")"ip6.arpa." | |
#Result: 4.3.3.7.0.7.3.0.e.2.a.8.0.0.0.0.0.0.0.0.3.a.5.8.8.b.d.0.1.0.0.2.ip6.arpa. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment