Guest User

Untitled

a guest
Jul 15th, 2012
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. trying to make simple WakeOnLan script with PHP
  2. <?php
  3.  
  4. //check if server is up and running
  5. $alive = fsockopen("XXX.168.1.1", 80, $errno, $errstr, 2);
  6.  
  7. if (!$alive) {
  8. echo "<h1>Server is Down!</h1>";
  9. echo "I will try to turn it on now...";
  10.  
  11. //Creating magic packet
  12. $mac_address = str_repeat("XXX5XXXX5XXX", 16);
  13. $msg = "FFFFFFFFFFFF " . "$mac_address" . "000000000000";
  14. $host_addr = "XXX.168.1.1";
  15. $host_port = "X";
  16.  
  17. //Connect send and close connection
  18. $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  19. $socket_data = socket_send($socket, $msg, strlen($msg), 0, $host_addr, $host_port);
  20.  
  21. socket_close($socket);
  22. //testing
  23. //echo
  24. } else {
  25. echo "<h1>Server is Up!</h1>";
  26. fclose($alive);
  27. }
  28.  
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment