目錄 |
要指定可以Wake On LAN
下載 cgi模式工具,已有完整功能,含 php 版本。
使用 php 撰寫 "Magic Packet",程式來源:WOL: Wake-on-LAN Tutorial with Bonus PHP Script
參考資料:Wake-on-LAN
<?
# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
# Modified by Allan Barizo http://www.hackernotcracker.com
flush();
function WakeOnLan($addr, $mac,$socket_number) {
$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));
return FALSE;
}
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";
return FALSE;
}
if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
echo "Magic Packet sent successfully!";
socket_close($s);
return TRUE;
}
else {
echo "Magic packet failed!";
return FALSE;
}
}
}
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
$socket_number = "7";
// MAC Address of the listening computer's network device
$mac_addy = "00:12:4G:SF:12:13";
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
$ip_addy = gethostbyname("myhomeserver.dynamicdns.org");
WakeOnLan($ip_addy, $mac_addy,$socket_number)
?>
ubuntu 中可安裝 wakeonlan 套件,指令 例:
wakeonlan 01:23:45:67:89:ab
wakeonlan -p 7 01:23:45:67:89:ab
解決的方法:
#!/bin/bash #使用的網路卡 eth0 or eth1 ethtool -s eth0 wol g ethtool -s eth1 wol g ethtool -s eth2 wol g exit
注意:教室全部派送前可能要先移除 /etc/udev/rules.d/70-persistent-net.rules ,卡號才不會亂命名。
參考資料:Wake-on-LAN
四樓電腦教室 mac 表
# maclist - mac addresses for wakeonlan 00:09:73:79:a8:5b st01 00:09:73:c7:a0:5b st02 00:09:73:24:6c:4d st03 00:09:73:8f:6c:4d st04 00:09:73:2d:81:4d st05 00:09:73:e4:6b:4d st06 00:09:73:39:6c:4d st07 00:09:73:74:82:4d st08 00:09:73:24:6a:4d st09 00:09:73:87:a8:5b st10 00:09:73:91:a8:5b st11 00:09:73:a9:71:4d st12 00:09:73:6a:a9:5b st13 00:09:73:70:7a:4d st14 00:09:73:64:a8:5b st15 00:09:73:7b:b0:5b st16 00:09:73:28:a8:5b st17 00:09:73:bb:a8:5b st18 00:09:73:fd:6a:4d st19 00:09:73:02:a8:5b st20 00:09:73:19:a8:5b st21 00:09:73:22:6c:4d st22 00:09:73:ca:6b:4d st23 00:09:73:6f:a8:5b st24 00:09:73:f0:a7:5b st25 00:09:73:8d:6d:4d st26 00:09:73:bd:9f:5b st27 00:09:73:95:a9:5b st28 00:09:73:82:6d:4d st29 00:09:73:c7:6c:4d st30 00:09:73:c6:6b:4d st31 00:09:73:ef:71:4d st32 00:09:73:fb:6e:4d st33 00:09:73:67:a9:5b st34 00:09:73:d9:a8:5b st35 00:09:73:25:6a:4d st36