Witam!
Posiadam router na którym mam przekierowany port 9 na adres jednego z komputerów sieci LAN (192.168.1.104) oraz na stałe ustawiony IP & MAC Binding.
Używając tej strony http://www.wakeonlan.me/ wpisuję adres mac karty i zewnętrzny adres IP i komputer bez problemu się wybudza.

Próbuję znaleźć podobny skrypt abym mógł wybudzać komputer z własnego serwera. Znalazłem coś takiego:

  1. function wol_magic_packet($mac,$addr='255.255.255.255') {
  2. //Requirements__________________________
  3. // You need to load the php_sockets.dll (in case of Windows, don't
  4. // know @ linux, compile with --socket-support i beleave ).
  5. // Otherwise he cannot find the socket_create function
  6. //Usage________________________________
  7. // $addr:
  8. // You will send and broadcast tho this addres.
  9. // Normaly you need to use the 255.255.255.255 adres, so i made it as default. So you don't need
  10. // to do anything with this.
  11. // $mac:
  12. // You will WAKE-UP this WOL-enabled computer, you need to add the MAC-addres here.
  13. //
  14. //Return________________________________
  15. // TRUE: When socked was created succesvolly and the message has been send.
  16. // FALSE: Something went wrong
  17. //
  18. //Example_1_____________________________
  19. // When the message has been send you will see the message "Done...."
  20. //
  21. // if ( wol_magic_packet ( '00:00:00:00:00:00' ) )
  22. // echo 'Done...';
  23. // else
  24. // echo 'Error while sending';
  25. //
  26. //Example_2_____________________________
  27. // To loop more computers:
  28. //
  29. // $arr = array(
  30. // '00:00:00:00:00:00',
  31. // '00:00:00:00:00:00'
  32. // );
  33. // foreach($arr as $this_id => $this_mac)
  34. // if (! wol_magic_packet ( $this_mac ))
  35. // echo 'Error while sending to ['. $this_mac .']<br />'."\r\n";
  36. //___________________________________________
  37.  
  38. //Check if it's an real MAC-addres and split it into an array
  39. if (!preg_match("/([A-F0-9]{2}[-:]){5}[A-F0-9]{2}/",$mac,$maccheck))
  40. return false;
  41. $addr_byte = preg_split("/[-:]/",$maccheck[0]);
  42.  
  43. //Creating hardware adress
  44. $hw_addr = '';
  45. for ($a=0; $a < 6; $a++)//Changing mac adres from HEXEDECIMAL to DECIMAL
  46. $hw_addr .= chr(hexdec($addr_byte[$a]));
  47.  
  48. //Create package data
  49. $msg = str_repeat(chr(255),6);
  50. for ($a = 1; $a <= 16; $a++)
  51. $msg .= $hw_addr;
  52.  
  53. //Sending data
  54. if ( //If
  55. function_exists('socket_create') AND //socket_create exists
  56. $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP) AND //Can create the socket
  57. $sock_data = socket_connect($sock, $addr, 2050) //Can connect to the socket
  58. ) { //Then
  59. $sock_data = socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); //Set
  60. $sock_data = socket_write($sock, $msg, strlen($msg)); //Send data
  61. socket_close($sock); //Close socket
  62. return true;
  63. } else //Esle? tongue.gif
  64. return false;
  65. }
  66.  
  67. wol_magic_packet('00:C1:26:0A:6E:88', 'zewnętrzny adres IP');
  68. ?>


Jednak nie chce działać, działa jedynie na lokalnym serwerze kiedy zamiast zewnętrznego IP wpiszę IP broadcast.
Oczywiście na obydwu serwerach włączona jest biblioteka php_sockets.dll.
Jak sobie z tym poradzić aby wybudzać komputer przez internet?