我有这样一个结构的文件:
08.176.250.200-108.176.250.219
108.176.251.40-108.176.251.163
108.176.254.212-108.176.254.215
108.176.254.216-108.176.255.87
108.177.224.0-108.177.225.255
108.179.0.32-108.179.0.87
108.179.0.192-108.179.0.255
108.179.4.0-108.179.4.255
108.179.13.0-108.179.13.255
108.179.18.0-108.179.18.15
108.179.18.16-108.179.19.255
108.179.25.0-108.179.25.255
108.179.32.16-108.179.33.255
108.179.42.64-108.179.42.255
如何将它们转换为CIDR并保存到新文件?
最佳答案
您可以使用ipcalc
从IP范围计算cidr
:
~/test$ ipcalc -rn 108.179.42.64-108.179.42.255
deaggregate 108.179.42.64 - 108.179.42.255
108.179.42.64/26
108.179.42.128/25
下面将计算文件(
ip.txt
)每行的IP范围并将其存储在cidr.txt
中:awk '{system("ipcalc -rn "$1 "| tail -n +2")}' ip.txt > cidr.txt
或使用
xargs
:<ip.txt xargs -I '{}' bash -c 'ipcalc -rn {} | tail -n +2' > cidr.txt
关于linux - 将IP范围列表转换为cidr,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41325084/