将ip范围列表转换为cidr

时间:2016-12-25 22:52:34

标签: linux awk grep

我有这样的结构文件:

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并保存到新文件?

1 个答案:

答案 0 :(得分:7)

您可以使用ipcalc从IP范围计算select count(distinct flow_id) as work_sum, count(distinct IF(ISHANDLE=2, FLOW_ID, NULL)) as ERROR_SUM FROM Table as A GROUP BY ALERT_USER

cidr

以下内容将计算文件每一行的IP范围(~/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中:

cidr.txt

awk '{system("ipcalc -rn "$1 "| tail -n +2")}' ip.txt > cidr.txt

xargs