在用awk處理文字時,有些場景需要將簡化的ipv6位址補充成完整的ipv6位址,下邊函式可簡單實現:
# ipv6位址補全函式
function compipv6(orig_address)
else if ( length(ip_field[i]) == 1 )
else if ( length(ip_field[i]) == 2 )
else if ( length(ip_field[i]) == 3 )
# 組合臨時簡化的ipv6位址
if ( i==1 )else
}# 迴圈補全32位do}
else if( $nf != "0000" )
}fs=" "
}while(0)
# 判斷原始資料是否有掩碼位,有則需要返回掩碼位
if (orig_address !~ /\//)
else
}
vrf chinamobile_sgi
rd 24059:4600
address-family ipv6 unicast
network 2409:8005:800::/127
network 2409:8005:800::8/127
network 2409:8005:800::10/127
network 2409:8005:800::1c/127
network 2409:8005:800::24/127
network 2409:8015:800::/120
network 2409:8015:800::100/120
network 2409:8015:800:1::/64
network 2409:8015:800:2::/64
network 2409:8015:870::/44
network 2409:8015:880::/43
network 2409:8127:f200::/44
network 2409:8127:f210::/44
network 2409:8127:f220::/44
network 2409:8127:f240::/44
network 2409:8805:800::/43
network 2409:8805:820::/43
network 2409:8805:840::/44
network 2409:8805:850::/44
network 2409:8805:860::/43
network 2409:8805:8a0::/43
network 2409:8805:8c0::/43
! !
#!/bin/awk -f
# author: wholj
# date: 2018-12-21
# ipv6位址補全函式
function compipv6(orig_address)
else if ( length(ip_field[i]) == 1 )
else if ( length(ip_field[i]) == 2 )
else if ( length(ip_field[i]) == 3 )
# 組合臨時簡化的ipv6位址
if ( i==1 )else
}# 迴圈補全32位do}
else if( $nf != "0000" )
}fs=" "
}while(0)
return full_addr"/"ipv6_addr[2]
}# awk開始處理傳入的文字檔案
}
2409:8005:800::/127 --> 2409:8005:0800:0000:0000:0000:0000:0000/127
2409:8005:800::8/127 --> 2409:8005:0800:0000:0000:0000:0000:0008/127
2409:8005:800::10/127 --> 2409:8005:0800:0000:0000:0000:0000:0010/127
2409:8005:800::1c/127 --> 2409:8005:0800:0000:0000:0000:0000:001c/127
2409:8005:800::24/127 --> 2409:8005:0800:0000:0000:0000:0000:0024/127
2409:8015:800::/120 --> 2409:8015:0800:0000:0000:0000:0000:0000/120
2409:8015:800::100/120 --> 2409:8015:0800:0000:0000:0000:0000:0100/120
2409:8015:800:1::/64 --> 2409:8015:0800:0001:0000:0000:0000:0000/64
2409:8015:800:2::/64 --> 2409:8015:0800:0002:0000:0000:0000:0000/64
2409:8015:870::/44 --> 2409:8015:0870:0000:0000:0000:0000:0000/44
2409:8015:880::/43 --> 2409:8015:0880:0000:0000:0000:0000:0000/43
2409:8127:f200::/44 --> 2409:8127:f200:0000:0000:0000:0000:0000/44
2409:8127:f210::/44 --> 2409:8127:f210:0000:0000:0000:0000:0000/44
2409:8127:f220::/44 --> 2409:8127:f220:0000:0000:0000:0000:0000/44
2409:8127:f240::/44 --> 2409:8127:f240:0000:0000:0000:0000:0000/44
2409:8805:800::/43 --> 2409:8805:0800:0000:0000:0000:0000:0000/43
2409:8805:820::/43 --> 2409:8805:0820:0000:0000:0000:0000:0000/43
2409:8805:840::/44 --> 2409:8805:0840:0000:0000:0000:0000:0000/44
2409:8805:850::/44 --> 2409:8805:0850:0000:0000:0000:0000:0000/44
2409:8805:860::/43 --> 2409:8805:0860:0000:0000:0000:0000:0000/43
2409:8805:8a0::/43 --> 2409:8805:08a0:0000:0000:0000:0000:0000/43
2409:8805:8c0::/43 --> 2409:8805:08c0:0000:0000:0000:0000:0000/43
IPv6知識概述 IPv6位址
首選格式 x x x x x x x x x表示乙個4位十六進製制數 典型的例子如下所示 2000 0000 0000 0000 0001 2345 6789 abcd ipv6位址每段中的前導0是可以去掉的,但是至少要保證每一段有乙個數字。將不必要的前導0去掉後,上述位址可以表示為 2000 0 ...
申請IPV6位址配置IPV6網域名稱
0.前言 最近弄了一下ipv6,雖然不知道什麼時候會用到,但是伺服器支援ipv6,還是有必要的。1.申請ipv6位址 到這個 去註冊乙個帳號,然後建立乙個隧道。第一次開啟這個頁面,一股80 90年代的 風格。註冊時郵箱要寫合法郵箱,要收驗證碼的。然後檢視tunnel資訊 按照提示配置好ecs伺服器網...
申請IPV6位址配置IPV6網域名稱
0.前言 最近弄了一下ipv6,雖然不知道什麼時候會用到,但是伺服器支援ipv6,還是有必要的。1.申請ipv6位址 到這個 去註冊乙個帳號,然後建立乙個隧道。第一次開啟這個頁面,一股80 90年代的 風格。註冊時郵箱要寫合法郵箱,要收驗證碼的。然後檢視tunnel資訊 按照提示配置好ecs伺服器網...