I have ip and I want to convert it into CIDR block with specific mask (/28, for example). Using PHP.
So that input "1.1.1.100" and "28" and output is "1.1.1.96/28"
ip_to_cidr('1.1.1.100', '28') // '1.1.1.96/28'
I found a lot of functions to match and ranges, but nothing about actually converting from ip to CIDR. Seems like to be most basic operation, may be I am missing something, using wrong search terms or misunderstanding masks.
For context: I need to block bots, I have their IP and want to block range in ipset. /24 is a bit to much (but easy to make, just replace last bit with ".0/24"), so I want to use /27 /28 /29.