PHP-WoL with Port Check (similar to ping)

Don't miss a thing. Post your questions and discussion about other uncategorized NAS features here.
Post Reply
PRThomasUK
Starting out
Posts: 10
Joined: Tue Nov 06, 2007 5:15 am
Location: Slough, UK

PHP-WoL with Port Check (similar to ping)

Post by PRThomasUK »

Hi Guys,
I've owned a QNAP TS109-Pro for sometime now, I really should upgrade but it just keeps going and does what I need and has been running 24/7 since I purchased it...

I've been running a rather basic PHP page from my QNAP to Wake on LAN (WoL) my computer from wherever I am. It worked well and always woke up my PC, however it didn't give any feedback other then the WoL packet was sent! I would therefore have to keep trying to connect to my PC until succesfull. I had a look around for another script that used "PING" to check if the PC was on... It seems running "PING" from "PHP" on the QNAP isn't really possible! I nearly gave up but whilst looking around on the Internet I found a bit of PHP that would open a socket connection to a port on a device. Logically if I can create a connection to my PC it must be ON! Eureka....

I'm no expert with PHP or HTML, however after a few hours of coding I managed to put together exactly what I wanted... A single PHP file that would wake up my PC and report back when it was actually on!

The page generates a FRAMESET (Generally frowned upon, but works well with most modern browsers!) The top frame loads once and sends the WoL packet, the bottom frame then keeps reloading until a connection is made out, or the maximum number of tries is reached...

You can download the PHP source from my blog :-

http://www.pete-thomas.me.uk/2013/04/ph ... ke-on-lan/
Last edited by PRThomasUK on Wed Apr 23, 2014 4:45 am, edited 1 time in total.
** QNAP TS-109 Pro / v1.1.3 build 1101T **
HenkNL
Starting out
Posts: 13
Joined: Sun Aug 24, 2008 10:46 pm

Re: PHP-WoL with Port Check (similar to ping)

Post by HenkNL »

Thank you ! Perfect script. It runs on my qnap119 24hrs a day.

Even on my PopcornHour C200 it works. There it doesn't show the PHP-wol page but it wakes the selected wol-device (Netgear Ultra6 nas) just fine.

Henk
cstubley
Starting out
Posts: 26
Joined: Tue Jan 25, 2011 7:44 am

Re: PHP-WoL with Port Check (similar to ping)

Post by cstubley »

Just what I was looking for! Thanks a lot. :)
ChiefORZ
Starting out
Posts: 17
Joined: Tue Apr 03, 2012 3:52 pm

Re: PHP-WoL with Port Check (similar to ping)

Post by ChiefORZ »

nice script, thanks a lot
... by the way ... was someone hearing about a coming update to PHP ?
User avatar
rugolt
New here
Posts: 3
Joined: Sun Feb 26, 2012 1:42 am

Re: PHP-WoL with Port Check (similar to ping)

Post by rugolt »

Does anybody still have this script? Need something to wake up a computer from my NAS.
User avatar
OneCD
Guru
Posts: 12156
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: PHP-WoL with Port Check (similar to ping)

Post by OneCD »

rugolt wrote:Does anybody still have this script? Need something to wake up a computer from my NAS.
I did some searching for this. Looks like Pete Thomas's old site has been pulled down, and his new one never made it past the setup stage. :'

But Google found a Danish QNAP user who reposted Pete's work:
Klaus Rafn Andersen wrote: By Klaus Rafn Andersen 3. June 2015

Setting up the feature of WoL – meaning: Wake on Lan – on a QNAP server, can sometimes be difficult for people.
Several years ago, a guy named Pete Thomas, wrote a nice script for the exact purpose of WoL’ing. I just changed the variables as described here:

1. First of all, enable WoL in the “System Settings” menu tab “Power” and shut down the server.
2. Download the php source for the wake-up script here and rename it from .txt to .php
3. Edit the script so it match your specific system (see further down below).

You need the following info for the server:
A) MAC address
B) LAN IP address
C) WoL port number (for QNAP it is port 7)
D) A Port number for checking if the server is awake (I recommend 8080 on QNAP)
E) A descriptive name for the sleeping server.

Now execute the script from anywhere in the LAN and your server will boot.

##################################################
## php WoL with port check – PRThomasUK. ##
## blog.pete-thomas.me.uk ##
##################################################
//
// ################## user variables… ##################
// Friendly name for device, example “My Computer”.
$device = “Write a name identifying your server”;
// IP address of device, example “x.x.x.x”.
$deviceip = “the internal LAN ip address of your server”; e.g. “192.168.1.1”
// TCP Port on device to check, example “3389” = RDP, “80” = WebServer.
$deviceport = “port no.”; e.g. “8080”
// MAC address of NIC1 on device, example “00:00:00:00:00:00” or “00-00-00-00-00-00”.
$devicemac1 = “The MAC address of the LAN card in your server”; e.g. “00:08:9a:8a:12:01”;
// MAC address of NIC2 on device, example “00:00:00:00:00:00” or “00-00-00-00-00-00”. – Optional set to “” if NIC2 not required.
$devicemac2 = “”;
// Number of times to attempt to connect to port on device after magic packet sent, example “10”
$maxtries = “10”;
// Broadcast address of network, example “”x.x.x.x”. (“255.255.255.255” works in most cases.)
$broadcast = “255.255.255.255”;
// ICMP port number, default “7”.
$udport = “7”;
// Timeout value for re-tries (in seconds), default “10”.
$timeout = “15”;
// #######################################################

Do not change anything else….
And here's the PHP source again:
PHP-WoL.php_.zip
Hope this helps. ;)
You do not have the required permissions to view the files attached to this post.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Post Reply

Return to “Miscellaneous”