Created
May 7, 2020 16:00
-
-
Save SaigyoujiYuyuko233/6320b34bc3e0e7e73e61b71e910104ed to your computer and use it in GitHub Desktop.
Covert netmask(255.255.255.0) to cidr(/24)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function netmask2Cidr($startIP = "10.198.12.0", $endIP = "10.198.12.255") { | |
$margin = strlen(decbin((ip2long($endIP) - ip2long($startIP)))); | |
$netmask = decbin(0xFFFFFFFF << $margin & 0xFFFFFFFF); | |
return substr_count($netmask, "1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment