Skip to content

Instantly share code, notes, and snippets.

@edmhs
Last active May 24, 2017 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edmhs/8bdc99b5f69072cb5ade4b36e8630429 to your computer and use it in GitHub Desktop.
Save edmhs/8bdc99b5f69072cb5ade4b36e8630429 to your computer and use it in GitHub Desktop.
Return array with all ip addreses from ip addresses subnet - PHP Subnet mask calculator
<?php
$range = "194.8.42.0/24";
function ipListFromRange($range){
$parts = explode('/',$range);
$exponent = 32-$parts[1].'-';
$count = pow(2,$exponent);
$start = ip2long($parts[0]);
$end = $start+$count;
return array_map('long2ip', range($start, $end) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment