Verify if IP works or not - Intranet
Moderator: General Moderators
Verify if IP works or not - Intranet
I'm working on an intranet webpage, and I can't figure out something. I got a list of Devices with IPs and I want PHP to verify if they are active or not. Except, my boss keeps forgetting I'm NOT a networking/programming major. I'd really like a hand in this. I tried googleling but I only found PC Software. =/
~RB
~RB
I found this piece of code:
The $ip part I got, but I assume $errno and $errstr have to mean something. I tried it the way it stands, and the page just doesn't load.
Code: Select all
<?php $up = @fsockopen("$ip", 80, $errno, $errstr, 30);
if($up)
{
echo 'Online';
}
else
{
echo 'Offline';
} ?>- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
The problem with fsockopen is that you need to be able to connect to an open port on the other machine. Using a simple icmp ping would be better (but don't forget you can set a firewall to ignore icmp packets). You'll need to do some string comparisons on the result of your exec()'s too.ole wrote:If these are remote IP over the internet then it can't be reliably done due to firewalls.I got a list of Devices with IPs and I want PHP to verify if they are active or not.
If these are on a local network fsockopen and `ping $ip` etc commands should be good.
Red Blaze
What do you consider up? Apache (MS ISS) is up? PHP is up? MySQL (MSSQL/ORACLE) is up?
If you are checking for the above things. You could write a simple web service. When that web service is called it connects and disconnects from your database. Then it returns a predetermined response. If you get that predetermined response back you know Apache/PHP/MySQL is up and running. If you don't. Something is wrong and needs attention.
If you're in the Linux environment you could even setup a simple CRON job with cURL to check the status on a regular basis. If you're in the Windows enviroment, well I can't help you there because I'm not as familiar with Windows.
- Eric
What do you consider up? Apache (MS ISS) is up? PHP is up? MySQL (MSSQL/ORACLE) is up?
If you are checking for the above things. You could write a simple web service. When that web service is called it connects and disconnects from your database. Then it returns a predetermined response. If you get that predetermined response back you know Apache/PHP/MySQL is up and running. If you don't. Something is wrong and needs attention.
If you're in the Linux environment you could even setup a simple CRON job with cURL to check the status on a regular basis. If you're in the Windows enviroment, well I can't help you there because I'm not as familiar with Windows.
- Eric
Most devices talk http://www.php.net/snmp these days...
I've been trying to use this bit of code:
It works for the first three, but then it tells me this:
Code: Select all
$ip = $row_records['IP'];
if($ip == "Not Available"){
echo 'Offline';
}else{
exec("ping $ip");
}I think I'm forcing the server with that, but... really, I barely know what I'm doing. ~_~Fatal error: Maximum execution time of 30 seconds exceeded in ********/index.php on line 99
Ping makes a lot of trips before it end itself, quite a few more than you need to determine if the device is up or not. Try this:
Also, you can increase the time that PHP will execute a script before it throws the error that you are getting.
Reference for ini_set() http://us3.php.net/manual/en/function.ini-set.php
Reference for ini configurations http://us3.php.net/manual/en/ini.php#ini.list
- Eric
Code: Select all
exec("ping -c 3 $ip");Reference for ini_set() http://us3.php.net/manual/en/function.ini-set.php
Reference for ini configurations http://us3.php.net/manual/en/ini.php#ini.list
- Eric
That makes everything load, however, when I echo it, it doesn't display anything. Is it just ignoring it? I found out just now that it's actually Windows and not Linux. My apologies. >_<
EDIT: When I echo this:
It displays this first:
EDIT: When I echo this:
Code: Select all
echo exec("ping $ip");It displays this first:
Then it does this in another row:Minimum = 0ms, Maximum = 0ms, Average = 0ms
Then the third row, it gives me the Time Exceeded error.Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)
Looks to me like the host your trying to ping is unreachable from your server.
Have you logged into the web server and tried pinging the devices from there?
Also you might try a test script to make sure everything is okay with your server configuration by pinging a host you know should work. Such as
- Eric
Have you logged into the web server and tried pinging the devices from there?
Also you might try a test script to make sure everything is okay with your server configuration by pinging a host you know should work. Such as
Code: Select all
echo exec("ping http://www.yahoo.com");