mapcidr
mapcidr copied to clipboard
Greatly optimize filter and match performance
example data: ip.txt:
1.25.242.23/32
1.71.150.96/29
54.240.128.0/20
cdn:
109.199.57.0/24
101.79.149.0/24
116.128.128.0/24
115.231.186.0/24
103.22.200.0/22
61.155.165.0/24
113.20.148.0/23
185.254.242.0/24
59.36.120.0/24
70.132.0.0/18
52.78.247.128/26
110.93.176.0/20
54.240.128.0/18
46.51.216.0/21
70.132.0.0/16
104.16.0.0/12
121.12.98.0/24
103.31.4.0/22
204.246.164.0/22
42.236.6.0/24
125.88.190.0/24
61.54.47.0/24
103.27.12.0/22
116.193.80.0/21
131.0.72.0/22
192.230.64.0/18
220.191.231.0/24
59.82.0.0/16
old:
$ time mapcidr -cl ip.txt -fi cdn.txt -silent
1.25.242.23
1.71.150.96
1.71.150.97
1.71.150.98
1.71.150.99
1.71.150.100
1.71.150.101
1.71.150.102
1.71.150.103
real 0m11.365s
user 0m0.000s
sys 0m0.000s
optimizated:
$ time mapcidr -cl ip.txt -fi cdn.txt -silent
1.25.242.23/32
1.71.150.96/29
real 0m0.051s
user 0m0.000s
sys 0m0.016s
Time complexity from n^n to n*n (mybe, I did not calculate in detail)
https://github.com/projectdiscovery/mapcidr/pull/107/commits/53d4cf19f25c254cdee892156866c60db21d614a Resolved.
test case1:
Some integration tests are failing
and
Results tends to be cidr
mapcidr -cl ip.txt -fi 192.168.1.1,192.168.1.3 -silent
ip.txt:
192.168.1.0/30
output:
192.168.1.0
192.168.1.2
test case2:
it seems like IPv4-mapped IPv6 addresses are now represented only as ipv4 (see failing integration tests)
mapcidr -cl ip.txt -fi cdn.txt -silent
ip.txt:
2002:0000:0000:0000:0000:0000:c0a8:0101
2002:0000:0000:0000:0000:0000:c0a8:0104
cdn.txt:
2002:0000:0000:0000:0000:0000:c0a8:0101
2002:0000:0000:0000:0000:0000:c0a8:0103
output:
2002::c0a8:104
SonarCloud Quality Gate failed. 
0 Bugs
0 Vulnerabilities
2 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
now, all integration tests pass, lol
While testing ipv4/ipv6, further inconsistencies were detected - For the time being. I'm closing it as not planned for the time being as the library it's heavily used with other tools.