Hi
This is my problem:
I currently developing an Iplist site for my company. One of the features I want is an automatic ping. This means, when you like to add an IP nr you should be able to see it it has been alive for some time. I want to maka a seach for an IP and find out for how long it has been alive or iif its not currently being used. The Iplist server should ping the entire 192.168.0 network everyday and put the information in a table in Mysql. I am using a Linux server so what Im thinking of is to somehow use the crontab. From the crontab format the information and parse it to my DB.
Please help me with this. Im pretty new to PHP and dont know a lot about the features.
By the way do someone know of an IPlist solution with these functions:
Add/Remove IP
Add/Remove Net
See if the hosts has been alive for a while
Automatic Reverse DNS lookup
Show Nat mapping to external addresses
Info on who checks out the IP/Net
PHP ping
Moderator: General Moderators
Here's a start for you:
/Edit: Added a bracket.
Code: Select all
<?php
for ($i = 1; $i <= 255; $i++)
{
if(ping("192.168.0".$i))
{
//ping sucessful
//insert into database
}
else
{
//ping failed
//insert into database
}
}
function ping($ip)
{
$str=exec("ping -c 1 -w ".$ip.",$a,$a1);
if(strlen($str)>1)
{
return true;
}
else
{
return false;
}
}
?>
Last edited by Grim... on Thu Jun 24, 2004 8:42 am, edited 4 times in total.
Apart from the syntax errors, many sysadmins restrict access to ping so it would be doubtful that your code would work. Also ping returns exit code 1 if it did not receive a reply, 2 on error and 0 for everything else, so checking the exit code would be a better way to go.Grim... wrote:Here's a start for you:Code: Select all
<?php for ($i = 1; $i <= 255; $i++) { if(ping("192.168.0.".$i) { //ping sucessful //insert into database } else { //ping failed //insert into database } } function ping($ip) { $str=exec("ping -c 1 -w ".$ip.",$a,$a1); if(strlen($str)>1) { return true; } else { return false; } } ?>
Code: Select all
$str=exec("ping -c 1 -w ".$ip.",$a,$a1);