sensepost / gowitness

🔍 gowitness - a golang, web screenshot utility using Chrome Headless
GNU General Public License v3.0
3.23k stars 345 forks source link

HostsInCIDR improvement #107

Closed NickChillClub closed 2 years ago

NickChillClub commented 3 years ago

Changed the code for HostsInCIDR, It's easier from byte level. Changed info on the scan flags you are able to do comma separated as well. Changed a few lines to Sprintf as it's better to read.

leonjza commented 3 years ago

Thanks for the PR! 🙌

I think I might not understand this well (apologies for that!), but I worry a bit about the overall readability of HostsInCIDR after this change. Is there a specific problem this solves for CIDR calculation?

The rest of the changes look 👌 !

NickChillClub commented 3 years ago

There is no specific problem other than it's faster. I'm a big fan of optimising, faster code and better use of the Golang standard packages.
This is more efficient, cleaner and the same method is used in the other code languages for ages. To get the range of a cidr the easiest way is to convert it to integer. Then only what you have to do is increment. To check if it's a network or broadcast address you can check if the least significant byte is set to 0, in the last octet, with 0xFF and ignore if the result is 0 or 255.