11-25-2005, 06:06 PM | #1 |
Junior Member
Join Date: Nov 2005
Location: Ontario, Canada
Posts: 10
|
How to determine if a PC is on line?
I'm writing an inventory program that goes out and interrogates a PC for its hardware and software. However, before I do this I want to ensure that the PC is switched on and on line. How can I do this in PHP? I don't really want to shell out and PING the computer, I'm just hoping there's a more subtle method.
The network is all Windows, with XP Pro desktops/laptops and NT4/WK2003 servers. |
11-27-2005, 07:42 PM | #2 |
Administrator
Join Date: Nov 2005
Posts: 258
|
Maybe you can try something with fopen or file_exists? For example:
PHP Code:
Something like that maybe? I've never had to something like this to be honest, and I don't know of any other practical way (short of using shell and ping like you mentioned). |
11-28-2005, 08:47 PM | #3 |
Junior Member
Join Date: Nov 2005
Location: Ontario, Canada
Posts: 10
|
Well, after much digging around I discovered the fsockopen function on PHP.NET and cobbled together this little snippet of code:
PHP Code:
The other problem I had with this snippet was that if a PC is offline, I got a couple of PHP warnings that broke the display. Once again, Google to the rescue, I found that putting the "@" sign in front of the function suppressed the warnings. That was new one to me! |
11-29-2005, 04:39 PM | #4 |
Administrator
Join Date: Nov 2005
Posts: 258
|
Excellent way of doing it, the only downside is the need for 135 which is often blocked. But if it's only for internal use, it should be fine!
I'm going to wrap this up in a FAQ on PHPit. |
11-30-2005, 06:45 PM | #5 |
Junior Member
Join Date: Nov 2005
Location: Ontario, Canada
Posts: 10
|
Indeed, you are right, Dennis, port 135 may be blocked for security reasons. I am using this internally so the security risk isn't that great, and I also had to choose a port that I could guarantee to be available on our Windows workstations and servers. For anyone who's interested in finding other ports that may be used try this from a command line:
netstat -an |find /i "listening" |
12-02-2005, 09:06 PM | #6 |
Administrator
Join Date: Nov 2005
Posts: 258
|
I've posted this as a FAQ, available at http://phpit.net/faq/determining-if-a-pc-is-online/. Thanks for the tip!
|
Thread Tools | Search this Thread |
Display Modes | |
|
|