- 전체
- OpenSources
- Arts
- Scripts
- PHP
- CompterSystems
- Apps
- WebServer
- MANpage
- DigitalImaging
- Circuit
- ETC
- Hardware
- Synology
PHP WOL ( Wake-on-LAN) PHP Script
2009.02.12 01:27
URL (link) |
---|
http://www.hackernotcracker.com/2006-04/wol-wake-on-lan-tutorial-with-bonus-php-script.html
<?
# 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)
?>
# 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)
?>
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
7 | MP3 ID3-Tag 인코딩을 EUC-KR에서 UTF-8으로 변경하는 방법 [1] [1] | Shadow | 2011.04.12 | 58187 |
6 | [Chrome] YouTube Downloader [2] [1] | Shadow | 2012.04.05 | 45834 |
5 | VMware Workstation Tech Preview 2012 [1] | Shadow | 2012.04.02 | 43647 |
4 | Ubuntu + VMware-Server [1] | Shadow | 2010.08.12 | 40164 |
3 | [펌] 이기종간 GUI 원거리 접속 도구들 총집합 [3] | sukhyun | 2008.04.01 | 37742 |
2 | PuTTY (SSH Shell for Windows) | sukhyun | 2008.04.01 | 37709 |
1 | [GP] FileZilla | sukhyun | 2008.04.07 | 34077 |