在shell脚本中展开ipv6地址

cwe*_*ske 1 shell ipv6

我想基于给定的IPv6地址更新djbdns(dbndns)配置文件,例如2a01:488:66:1000:523:f116:0:1::1.

dbndns需要扩大IPv6地址,例如2a010488006610000523f116000000012a01:488:66:1000:523:f116:0:1.

扩展此类IPv6地址的最简单方法是什么?

San*_*ann 6

使用sipcalc可能会这样做.它提供了比你需要更多的信息,但一点grepcut能够解决:-)

$ EXPANDED=`sipcalc 2001::1 | fgrep Expanded | cut -d '-' -f 2`
$ echo $EXPAND
2001:0000:0000:0000:0000:0000:0000:0001
Run Code Online (Sandbox Code Playgroud)

作为参考,这是完整输出sipcalc:

$ sipcalc 2001::1
-[ipv6 : 2001::1] - 0

[IPV6 INFO]
Expanded Address        - 2001:0000:0000:0000:0000:0000:0000:0001
Compressed address      - 2001::1
Subnet prefix (masked)  - 2001:0:0:0:0:0:0:1/128
Address ID (masked)     - 0:0:0:0:0:0:0:0/128
Prefix address          - ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
Prefix length           - 128
Address type            - Aggregatable Global Unicast Addresses
Network range           - 2001:0000:0000:0000:0000:0000:0000:0001 -
                          2001:0000:0000:0000:0000:0000:0000:0001
Run Code Online (Sandbox Code Playgroud)