在shell脚本中扩展ipv6地址 [英] expand ipv6 address in shell script

查看:259
本文介绍了在shell脚本中扩展ipv6地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to update a djbdns (dbndns) configuration file based on a given IPv6 address, e.g. 2a01:488:66:1000:523:f116:0:1 or ::1.

dbndns需要扩展的IPv6地址,例如2a010488006610000523f11600000001表示2a01:488:66:1000:523:f116:0:1.

dbndns requires expanded IPv6 addresses, e.g. 2a010488006610000523f11600000001 for 2a01:488:66:1000:523:f116:0:1.

扩展这样的IPv6地址最简单的方法是什么?

What's the most simple way to expand such an IPv6 address?

推荐答案

使用sipcalc可能会做到.它提供了比您需要的更多的信息,但是一些grepcut可以解决此问题:-)

Using sipcalc might do it. It gives more information than you need, but a bit of grep and cut can solve that :-)

$ EXPANDED=`sipcalc 2001::1 | fgrep Expanded | cut -d '-' -f 2`
$ echo $EXPAND
2001:0000:0000:0000:0000:0000:0000:0001

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

For reference, this is the full output of 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

这篇关于在shell脚本中扩展ipv6地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆