P
P
pcdesign2019-06-19 09:09:09
Perl
pcdesign, 2019-06-19 09:09:09

How to shorten the list of IPs and turn it into a list of networks where possible?

There is a long list of IPs

10.2.186.8
10.2.186.64
10.2.186.65
172.7.143.6
172.7.143.33
172.7.143.34
172.7.143.35
и т.д.

At the output I would like to get:
10.2.186.8
10.2.186.64/31
172.7.143.6
172.7.143.33/30

How to implement it programmatically? To turn adjacent IPs into networks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
arto, 2019-06-27
@pcdesign

perl -MNet::CIDR::Lite -le 'print join"\n",Net::CIDR::Lite->new(@ARGV)->list' 10.2.186.8 10.2.186.64 10.2.186.65 172.7.143.6 172.7.143.33 172.7.143.34 172.7.143.35 
10.2.186.8/32
10.2.186.64/31
172.7.143.6/32
172.7.143.33/32
172.7.143.34/31

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question