jgreeno Posted July 17, 2007 Share Posted July 17, 2007 I'm trying to setup a page for our techs to use to determine which IPs are free in our DNS in a subnet that they supply. For instance they would type in 192.168.1 to see all free IPs in the 192.168.1.1-255 range. Here's my issue: I've tried the while, do_while and for and still the script only runs to the 42nd address before quitting. What am I missing? $l="0"; $finalp="."; for($l<=255; ;$l++){ $ipaddress=$record.$finalp.$l; $lookup=@gethostbyaddr($ipaddress); echo "<br>".$ipaddress." scanned.<br>"; if ($lookup==$ipaddress){ $data.="<b>".$ipaddress."</b> is free<br>"; echo "<b>".$ipaddress."</b> is free<br>"; } } Quote Link to comment Share on other sites More sharing options...
trq Posted July 17, 2007 Share Posted July 17, 2007 <?php $finalp="."; foreach(range(0,255) as $l) { $ipaddress = $record.$finalp.$l; $lookup=@gethostbyaddr($ipaddress); echo "<br>".$ipaddress." scanned.<br>"; if ($lookup==$ipaddress){ $data.="<b>".$ipaddress."</b> is free<br>"; echo "<b>".$ipaddress."</b> is free<br>"; } } ?> Quote Link to comment Share on other sites More sharing options...
jgreeno Posted July 17, 2007 Author Share Posted July 17, 2007 Also: $record is the subnet's forst 3 octets.. so: $record="192.168.1"; Quote Link to comment Share on other sites More sharing options...
jgreeno Posted July 18, 2007 Author Share Posted July 18, 2007 After some more troubleshooting I'm seeing that the loop works fine, it appears to be an issue with the amount of data that I'm pumping into the variable $data. After looking up only 42 addresses, the loop exits and does not execute subsequent commands. It's like the script just quits after 42 entries. Is there a logical limit to the amount of data that can be stored in a variable? Quote Link to comment Share on other sites More sharing options...
jgreeno Posted July 18, 2007 Author Share Posted July 18, 2007 I wonder is there's a limit to the number of DNS lookups that can be performed against and Active Directory DNS server in x amount of time.. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted July 18, 2007 Share Posted July 18, 2007 also, at the end of every look, maybe go unset($date); or maybe create an array value, that will store all your results? Quote Link to comment Share on other sites More sharing options...
jgreeno Posted July 18, 2007 Author Share Posted July 18, 2007 Am I even on the right track here? I feel like I'm so close and missing something stupid and simple.. <?php // Initialize some variables $finalp="."; $loop="0"; $record="192.168.1"; // 0 - 255 step loop while($loop <=255){ // Build the ip from the $record and the loop counter $ipaddress=$record.$finalp.$loop; // Do a lookup on the address $data=@gethostbyaddr($ipaddress); // If the lookup pukes, push the ip to an array value with loop counter as the key if ($data==$ipaddress){ $arr=array($loop => $ipaddress); } // Increment the counter $loop++; } // Feed the array to foreach and build the output foreach($arr as $output){ $output.=$output; } ?> Quote Link to comment Share on other sites More sharing options...
jgreeno Posted July 20, 2007 Author Share Posted July 20, 2007 also, at the end of every look, maybe go unset($date); or maybe create an array value, that will store all your results? So, how can I write values out of the loop and into an array for later use? My use of an array above seems to be overwritten every go round.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.