0

I want to write a PHP script similar to Enterprise Network Console, but for a LAN of PC's and devices instead of a WAN of servers.

I want to be able to check if the PC's, Copiers etc are connected to the network. I want to know even if they are off, however this is not possible as the PCs ignore packets unless it's a wake-on-lan packet, right?

What is the best way to check if a PC is on or off? I used fSocketOpen() to test the servers however most of the PC's aren't servers. They respond to pings but don't have ports open for connections, meaning PHP'ss fSocketOpen() won't work but pinging does.

user229044
  • 232,980
  • 40
  • 330
  • 338
CoderWalker
  • 299
  • 4
  • 14
  • 1
    Why would you try to do this in PHP? – user229044 Aug 09 '12 at 00:45
  • I need this to be accessible via a web interface as my section of the VLAN is one of many parts which are physically miles apart. – CoderWalker Aug 09 '12 at 00:47
  • 2
    I removed a *ton* of more or less fluff from your post, and edited it to ask a specific, answerable question, thus saving it from being closed. Your posts should contain *one question* and they should be as short as humanly possible. There was no reason what so ever for all that background info, just come out and *ask the question*. Also, please [don't add signatures or taglines to your posts](http://stackoverflow.com/faq#signatures). – user229044 Aug 09 '12 at 00:49
  • "Thanks" was for generosity of those who answer it wasn't being used as a "tag line". Also there is a huge problem with your edit. You removed crucial details, such as: range of devices (VOIP, copiers, desktops), information about the network, and an important part of the post (checking for new devices) I wouldn't classify it as fullf because it proivided detials so that I wouldn't get meny impossible answers. Thanks for not closing it though. Just think it may be confusing now. Should I make a post for each question? – CoderWalker Aug 09 '12 at 01:03
  • Looking at the original post, I have this comment: you want us to do all of this for you? I mean, read about network programming, then come back if you have questions. – netcoder Aug 09 '12 at 01:06
  • No, I'm just curious if it's possible using PHP exclusively and if anyone just happens to have knowledge about any piece of it that could be beneficial. Ex: How to ping devices in PHP,best way to setup the automated portion. (About net programming: I have been doing programming for 6 years, 3 of those being C# .NET and PHP/MySQL programming.) – CoderWalker Aug 09 '12 at 01:10
  • Your specific questions (sending WOL packets, pinging, etc.) already have been covered [either on Stack Overflow](http://stackoverflow.com/questions/6055293/wake-on-lan-scipt-that-works), or [in the manual](http://www.php.net/manual/en/function.socket-create.php#101012). You just have to search a little. – netcoder Aug 09 '12 at 01:11
  • I don't want to send WOL packets, I want to know if the machine is connected to the network. I think maybe my question is misleading. – CoderWalker Aug 09 '12 at 01:12
  • @CoderWalker: "*I want to know even if they are off*", well most machines don't respond to ICMP packets when off. If they do, well check the manual for a ping command, it's already in there and I already linked to it. Anyway, my point is: don't be lazy, think about it and search for it instead of asking someone else do it for you. – netcoder Aug 09 '12 at 01:14
  • @CoderWalker My edit made your question both answerable and suitable for this site. If you want to modify your question, you're free to do so. And the part where you signed your name, "Coby Walker", that was the signature I was talking about. – user229044 Aug 09 '12 at 01:55

1 Answers1

2

You can use system commands and catch the stdout for results.

Just make a search for PHP's popen ( http://uk3.php.net/popen ) examples.

echo run('ping 192.168.1.5');

function run($command) {
    $command .= ' 2>&1';
    $handle = popen($command, 'r');
    $log = '';

    while (!feof($handle)) {
        $line = fread($handle, 1024);
        $log .= $line;
    }

    pclose($handle);
    return $log;
}
Tim
  • 699
  • 8
  • 27
  • 1
    Don't bother with finding ports, creating sockets or imitating commands like ping. Use the OS' commands by executing them via PHP. I'm adding an example to my answer. – Tim Aug 09 '12 at 01:12