Search code examples
phpwindowsremote-accessremote-management

Check to see if computer is on


I have written a simple php page that sends wake-on-lan packets too a couple of my computers which are all running Windows 7.

How can I check if the computers are powered on (assuming the internet works at the location)?

Can I some how ping the computer when the page is loaded to check for a response?

Additional info: The computers are all at separate locations where they have dynamic dns setup for the IP and are all behind a router with other computers.


Solution

  • I can remote desktop all computers via windows RDC, I opened port 3389 for them as well as a seperate WOL port so they have two open ports

    Then try opening a remote desktop session?

    <?php
    $timeout = 10;
    $socket = @fsockopen( 'ip-of-the-client', 3389, $errno, $errstr, $timeout );
    $online = ( $socket !== false );
    
    var_dump( $online );
    

    The @ in the code is because fsockopen will throw a PHP Warning when a connection could not be made.

    EDIT: for the sake of clarity; 3389 is the default port used to create a remote desktop connection.