mapcidr icon indicating copy to clipboard operation
mapcidr copied to clipboard

Greatly optimize filter and match performance

Open M09Ic opened this issue 3 years ago • 1 comments
trafficstars

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)

M09Ic avatar Sep 22 '22 02:09 M09Ic

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

M09Ic avatar Oct 09 '22 09:10 M09Ic

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 2 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Nov 03 '22 07:11 sonarqubecloud[bot]

now, all integration tests pass, lol

M09Ic avatar Nov 03 '22 07:11 M09Ic

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.

Mzack9999 avatar Mar 09 '23 10:03 Mzack9999