Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm to sanitize file with addreses and remove nestet overlapping blocks #2

Closed
bldur opened this issue Sep 24, 2022 · 3 comments
Closed

Comments

@bldur
Copy link

bldur commented Sep 24, 2022

Can I leave this issue, for myself and someone else with time and desire to write or improve?

what i do now in shell, and would be nice feature in grepcidr.

Perfectly fine speed wise with more than 2000 lines and addres block that matches 5 as top hit, not sure if its misses or catches all, but should..

And well, i use prips to print out blocks /25 and smaller, which could be an option as it would be more lines with square scaling without.

sanitize_cidr() {

file="$1"
overlaps=$(cat $file | while read line ; do
                        echo "$(grepcidr -D $line $file | wc -l) $line\n"
                done | sort -r)
N=$(echo -e $overlaps | awk 'NR==1{print $1}')


# start with lowest N cidr with overlaps to highest in case they are nested.
for i in $(seq 2 $N) ; do
        echo -e $overlaps | grep "$i\s" | awk '{print$2}' | while read line ;do
                cidr_remove=$(grepcidr -D $line $file | sort -t "/" -k2 | tail -n+2 | sed -e 's/[]\/$*.^[]/\\&/g')
                for i in $cidr_remove ;do
                        sed -i "/$i/d" $file
                done
        done

done

}
Repository owner deleted a comment Jan 7, 2023
Repository owner deleted a comment Jan 7, 2023
@jrlevine
Copy link
Owner

jrlevine commented Jan 7, 2023

If you want to combine overlaping IP ranges, it's easy to do in a tiny script using the standard python ipaddress library, and probably other language libraries too. There's no need to add a wart to this program.

@jrlevine jrlevine closed this as completed Jan 7, 2023
@bldur
Copy link
Author

bldur commented Feb 18, 2023

This algorithm, as such, checkes for collisions between ranges and sets.
I do not think I can get it to run faster in shell.

As such, this wart belongs in cidrgrep.

Do something simple right, and as such, involving this is completion breaking naming is THE wart.

@jrlevine
Copy link
Owner

Like I said, this would be easy to do in a python script using the standard python ipaddress module. I am not going to add it to grepcidr.
If you don't have sufficient python skills and this is important to you, I'm sure you can find someone who'll program it for you, probably not for free.

Repository owner deleted a comment from bldur Feb 20, 2023
Repository owner deleted a comment from bldur Feb 20, 2023
Repository owner deleted a comment from thezoggy Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants