Can't create socket!\n";
echo "Error: '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
return FALSE;
}
else {
$opt_ret = socket_set_option($s, SOL_SOCKET, SO_BROADCAST, 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)) {
$content = bin2hex($msg);
echo "
\n";
echo "Magic Packet Sent!
\n";
echo "Port: ".$socket_number." MAC: ".$_GET['wake_machine']." Data: \n";
echo "
\n";
socket_close($s);
return TRUE;
}
else {
echo "Magic Packet failed to send!
\n";
return FALSE;
}
}
}
function PopulateMACList($maclist) {
// Takes an array in the format "key" => "mac"
// Cycles through the array
// Checks if MAC contains only valid caracters ( Aa-Ff 0-9 . : - )
// If valid, removes any ". : -" it finds
// Creates a tag with XX:XX:XX:XX:XX:XX format
foreach ($maclist as $host => $mac)
if (!preg_match('/[^A-Fa-f0-9\.-:]/',$mac)) {
$mac=preg_replace('/[^A-Fa-f0-9]/', "",$mac);
$mac=join(":",str_split($mac,2));
if (strlen($mac) == 17) {
echo " ".$host." \n";
}
}
}
?>