Rispondi al commento

Questo script lo lancio per accedere da remoto il mio computer usando il WOL (Wake on LAN).

Sul mio router ho impostato una regola di NAT che se riceve una richiesta UDP su una determinata porta la gira in broadcast alla mia rete locale.

In questo modo ottengo un Wake on LAN remoto.
Mi faccio inoltre mandare una mail di avviso.

Ammetto di non ricordare dove ho trovato lo script iniziale che poi ho modificato per le mie esigenze.

So solo che l'intestazione dello script riportava:

# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
# Modified by Allan Barizo http://www.hackernotcracker.com

Ecco il codice
include("Mail.php");

//Invia la mail usando la classe di pear
function Invia_Mail($mittente,$destinatario,$soggetto,$messaggio)
{
$recipients = $destinatario;
$headers["From"] = $mittente;
$headers["To"] = $destinatario;
$headers["Subject"] = $soggetto;

$body = $messaggio;

$params["host"] = "localhost";
$params["port"] = "25";
$params["auth"] = false;
$params["username"] = "";
$params["password"] = "";

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory("smtp", $params);
$mail_object->send($recipients, $headers, $body);
}

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));
}
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, $socket_number);
socket_close($s);
echo "Magic Packet sent (".$e.") to ".$addr;
}
}

// Port number where the computer is listening. Usually, any number between 1-40000 will do. Normally people choose 7 or 9.
$socket_number = "12345";
// MAC Address of the listening computer's network device
//$mac_addy = "FF:FF:FF:FF:FF:FF";
$mac_addy = "";
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
$ip_addy = "";

WakeOnLan($ip_addy, $mac_addy,$socket_number);
Invia_Mail("pippo@pluto.it","pippo@pluto.it","Attivazione WOW","Ciao Roberto,\nqualcuno ha attivato yoda usando il meccanismo WOW.\nSpero sia stato tu!");

Rispondi

Il contenuto di questo campo è privato e non verrà mostrato pubblicamente.
  • Elementi HTML permessi: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><table><tr><td>
  • Indirizzi web o e-mail vengono trasformati in link automaticamente
  • Linee e paragrafi vanno a capo automaticamente.
  • Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].

Ulteriori informazioni sulle opzioni di formattazione

CAPTCHA
Questa domanda serve a verificare che il form non venga inviato da procedure automatizzate
Image CAPTCHA
Enter the characters shown in the image.