0
CentOS Linux release 8.5.2111
Linux berry 5.4.60-v8.1.el8 #1 SMP PREEMPT Sun Aug 23 02:58:38 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
Raspberry PI 4 B

Hey guys, my php script is not able to send a magic packet in a local enviroment. I already tried disabling SELinux as recommended in many postings. I also deactivated the firewall-cmd. What could be the nature of the problem.

If you need further information's about the setup just ask and I will provide them as soon as possible.

sestatus

[root@berry html]# sestatus
SELinux status:                 disabled

php error

Warning: fsockopen(): unable to connect to udp://192.168.178.255:7 (Permission denied) in /var/www/html/index.php on line 20

Fatal error: Uncaught Exception: Cannot open UDP socket: Permission denied in /var/www/html/index.php:21 Stack trace: #0 /var/www/html/index.php(5): wakeUp('406186383D11', '192.168.178.255') #1 {main} thrown in /var/www/html/index.php on line 21

php script for WakeOnLAN

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');

wakeUp('40:61:86:38:3D:11', '192.168.178.255');

function wakeUp($macAddressHexadecimal, $broadcastAddress)
{
    $macAddressHexadecimal = str_replace(':', '', $macAddressHexadecimal);

    // check if $macAddress is a valid mac address
    if (!ctype_xdigit($macAddressHexadecimal)) {
        throw new \Exception('Mac address invalid, only 0-9 and a-f are allowed');
    }

    $macAddressBinary = pack('H12', $macAddressHexadecimal);

    $magicPacket = str_repeat(chr(0xff), 6).str_repeat($macAddressBinary, 16);

    if (!$fp = fsockopen('udp://' . $broadcastAddress, 7, $errno, $errstr, 2)) {
        throw new \Exception("Cannot open UDP socket: {$errstr}", $errno);
    }
    fputs($fp, $magicPacket);
    fclose($fp);
    
    echo 'send to '.$macAddressHexadecimal.' '.$broadcastAddress;
}

?>
Georodin
  • 191
  • 1
  • 2
  • 14

0 Answers0