Link to home
Start Free TrialLog in
Avatar of jericotolentino
jericotolentinoFlag for Philippines

asked on

Find out if a computer is online

Dear experts,

I'm not sure what I'm asking will be within the capabilities of PHP. Plain and simple, I'd like to check whether a computer is online using a PHP script. I know I can check if a server is online, but can this be done to a system that does not have web server software?

Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of sexshun
sexshun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If the computers are on a LAN behind a router or proxyserver - then thats pretty much impossiible
Avatar of sexshun
sexshun

what do you mean, routers and proxy servers can return ping.  Besides most computers are behind them anyway.  
Greetings,

What you could do is use dnsalias.com to setup a hostname to the computer.  The site also offers a free package which updates the ip address every so often.  Then what you could do is setup a dnsalias.com subdomain to point to the computer you wish to monitor and setup the ip updater on that computer.  Each time the ip address changes it will tell dnsalias the new ip address.  Then what you could do is a ping to the computerIwishtoMonitor.dnsalias.com and see if that responds.  Alternatively you could possibly host a web page on that computer and then call the page each time you want to see if it is online.  It should work with a firewall in communicating the updated ip address, but don't quote me on it.  Hope this helps.
Avatar of jericotolentino

ASKER

Hello everyone,

I'll be using this for our LAN only. Firewalls won't be a problem. I just need to monitor whether some computers are inaccessible (or cannot access) the network's resources. The computers here are about 50+ so I'll need an efficient solution like the ones you mentioned.

I've seen the code sexshun pointed me to, but I'll need to try it out first so I can see the effectiveness. I'll report back the results in a day or two. Thanks for your quick replies!
i don't think you can get more efficient than a standard ping.  
i agree with sexshun , most of the terminals are usually behind routers , not just one , but many.
Here is a quick way to see if you have internet connectivity. it will pull a given url and just do a pass/fail. Of course this only works if the url tha tyou are testing with is up. But hey, it is another way to do it.

<?php
if($data=file("http://www.whatismyip.com/")){
        echo "you are online\n";
}else{  
        echo "Offline\n";
}

?>
but how can we get any such info abt any remote computer ...?
say if we have an ip address, then what ?

you mean you want to check to see if a remote system is online. Well it depends on what services that the remote system has running. If it has a web server you can put just a small html page on it that you can pull with the above script that I posted. There are many services that  a system can run that you can connect to remotely to see it the system is up and responding. (FTP, NNTP, HTTP, TELNET, SSH........) all of these can be connected to remotely. If a connection to any or all is successful then you will know the system is up and on the network.

Hope this helps.
>>  i don't think you can get more efficient than a standard ping

I agree. I just used the exec function to execute ping and here's what I came up with.

<?php
$ipadd = "127.0.0.1";
$output = exec('ping ' . $ipadd,$output,$return);
if ($return == 0)
echo '<p>Online</p>';
else
echo '<p>Offline</p>';
?>

Since I have to deal with 50+ computers, I previously entered their IP addresses into the database and I'll use a loop to go through them.

Thanks for everyone's help!