Community discussions

 
User avatar
BartoszP
Forum Guru
Forum Guru
Topic Author
Posts: 1687
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

How to opitimize list of IP4 addresses

Thu May 02, 2019 11:43 pm

I was thinking how to optimize big IP lists before importing them to Mikrotik. It ended as this program.
Feel free to use it. Comments welcome.

Written with GNU Linux and gcc. Standard usage ... takes data from stdin and outputs to stdout

Program tries to merge consecutive IP addresses or IP ranges.
This list
10.10.10.4
10.10.10.5
10.10.10.6
10.10.10.7
192.168.1.128/32
192.168.1.129/32
192.168.1.130
192.168.1.131
192.168.1.132
192.168.1.133
192.168.1.134/32
192.168.1.135/32
192.168.1.136/29
192.168.2.128/31
192.168.2.130
192.168.2.131
192.168.2.132
192.168.2.133
192.168.2.134/32
192.168.2.135/32
192.168.2.136/29
192.168.2.144/28
172.16.1.1
1.1.1.1
8.8.8.8
9.9.9.9
172.16.1.2
172.16.2.0
172.16.2.1
172.16.1.3
is optimized to
192.168.2.128/27
192.168.1.128/28
10.10.10.4/30
172.16.1.2/31
172.16.2.0/31
1.1.1.1
8.8.8.8
9.9.9.9
172.16.1.1
Source:
optimizeip.c
Exapmple ip list:
testip.txt
Optimized list:
optimized.txt
You do not have the required permissions to view the files attached to this post.
Real admins use real keyboards.
 
nostromog
Member Candidate
Member Candidate
Posts: 109
Joined: Wed Jul 18, 2018 3:39 pm

Re: How to opitimize list of IP4 addresses

Sat May 04, 2019 5:53 pm

I think it is not working 100% right.

Example. Llet's get all facebook IPv4 address ranges and process them with your program:
$ (for orig in AS32934 AS63293 AS54115; do whois -h whois.radb.net -- "-i origin $orig"; done) | grep route: | awk '{print $2}' >facebook4.txt
$ gcc -o optimizeip optimizeip.c
$ ./optimizeip <facebook4.txt | grep 129
129.134.0.0/16
129.134.0.0/17
129.134.128.0/23
I still have had no time to study the code to look for the bug, but I wanted to warn you of this behaviour. The way I understand it 129.134.0.0/16 should be the only one left in the output
 
User avatar
BartoszP
Forum Guru
Forum Guru
Topic Author
Posts: 1687
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: How to opitimize list of IP4 addresses

Sat May 04, 2019 8:09 pm

Thank you for the report.
It is example of situation when one subnet is fully included in another. I do not look for such optimization ... yet :)
IMHO it is not "a bug" .. output is fully valid however not optimized to "deep roots".
Real admins use real keyboards.
 
ludvik
Frequent Visitor
Frequent Visitor
Posts: 55
Joined: Mon May 26, 2008 4:36 pm

Re: How to opitimize list of IP4 addresses

Fri May 17, 2019 10:42 pm

Who is online

Users browsing this forum: No registered users and 0 guests