Page 1 of 1

FSOCKOPEN broadcast fails/was:How to wake OTHER workstations

Posted: Wed Jan 12, 2011 5:00 pm
by MSE
Hello all!

I am working already for some time on the following goal: I want to wake up other workstations/servers using a PHP-page running on the QNAP TS-809U (Version 3.3.4 build 1019T) Please note: I do NOT want to wake up the Turbonas, but use it to wake other stations.

The target machine is WOL enabled and it works fine to wake it up using other WOL-tools on other workstations.

When trying the well known scripts (e.g. http://stephan.mestrona.net/wol/hilfe.php) nothing happens. Further investigation gave me the intention, that on the QNAP it is not allowed to create IPv4-UDP-sockets and/or to send broadcasts via this socket.
- Is this correct?
- Can this be configured?
- Are there any other solutions for this?

Best regards,
Markus Seifert (MSE)

FSOCKOPEN broadcast fails /was: How to wake OTHER workstatio

Posted: Thu Jan 13, 2011 5:30 pm
by MSE
Really odd:

fsockopen(udp://10.76.123.6, 7, $errno, $errstr, 4) ==>Error: 0
fsockopen(udp://10.76.255.255, 7, $errno, $errstr, 4) ==>Error: 13 Permission denied

It seems as if only broadcasts are not allowed. Any Hint?

Re: FSOCKOPEN broadcast fails/was:How to wake OTHER workstat

Posted: Thu Jan 13, 2011 6:05 pm
by MSE
Alternative does not work:

$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) ===> Error:13:Permission denied
socket_bind($sock,"0.0.0.0",7) ===> Error:13:Permission denied
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1) ===> Error:13:Permission denied
socket_sendto($sock, "Hello", strlen("Hello"), 0, "255.255.255.255", 7) ===> Error:13:Permission denied
socket_close($sock) ===> Error:13:Permission denied

Oddly the "socket_create" gives sometimes when reloading the page Error "116 No route to host" or "22 Invalid argument" ???

Really really odd...

Best regards,
Markus Seifert (MSE)

Re: FSOCKOPEN broadcast fails/was:How to wake OTHER workstat

Posted: Sat May 21, 2011 3:17 am
by osuse
Has someone found found a solution for this problem?

Or are there any other ideas how to perform a wakeon lan via the web interface?

Re: FSOCKOPEN broadcast fails/was:How to wake OTHER workstat

Posted: Sat May 21, 2011 3:33 pm
by P3R
I use the feature integrated in DD-WRT for that task.

Re: FSOCKOPEN broadcast fails/was:How to wake OTHER workstat

Posted: Mon Jun 06, 2011 10:18 pm
by osuse
I found the follwoing script on the official PHP site:

<?php
# Wake on LAN - (c) HotKey (at SPR dot AT), upgraded by Murzik <tomurzik@inbox.ru>

flush();

function WakeOnLan($addr, $mac)
{
$addr_byte = explode(':', $mac);
$hw_addr = '';

for ($a=0; $a < 6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));

$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);

for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;

// send it to the broadcast address using UDP
// SQL_BROADCAST option isn't help!!
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false)
{
echo "Error creating socket!\n";
echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
}
else
{
// setting a broadcast option to socket:
$opt_ret = socket_set_option($s, 1, 6, TRUE);
if($opt_ret < 0)
{
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
}
$e = socket_sendto($s, $msg, strlen($msg), 0, $addr, 2050);
echo $e;
socket_close($s);
echo "Magic Packet sent (".$e.") to ".$addr.", MAC=".$mac;
}
}

#WakeOnLan('yourIPorDomain.dyndns.org', 'your:MAC:address');
#WakeOnLan('192.168.0.2', '00:30:84:2A:90:42');
#WakeOnLan('192.168.1.2', '00:05:1C:10:04:05');

//if you have switch or other routing devices in LAN, sendign to
// the local IP isn't helps! you need send to the broadcast address like this:
WakeOnLan('192.168.0.255', 'xx:xx:xx:xx:xx:xx');

?>

It works perfect. The point is that by default broadcasts are disabled for sockeds. The socket_set_option command enables broadcast messages.

So have fun with it.

Re: FSOCKOPEN broadcast fails/was:How to wake OTHER workstat

Posted: Mon Mar 05, 2012 10:03 am
by SuperSalad
Installing Python from optware and doing it with Python? Long shot, but I figure maybe someone on the Internet will find this thread like I did...

wol.py

Code: Select all

import socket

s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto('\xff'*6+'\xe2\x33\x95\xc3\xff\xe4'*16, ('<broadcast>',9))
Where the MAC is E2:33:95:C3:FF:E4.