Created
August 5, 2024 01:05
-
-
Save djGrrr/4413dacee0df28429306e9fdf4624e02 to your computer and use it in GitHub Desktop.
WAS-110 Multicast Upgrader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$source_ip = '192.168.1.2'; | |
$source_port = 0; | |
$dest_ip = '192.168.1.1'; | |
$dest_port = 13456; | |
$block_size = 1436; | |
############################################################################### | |
function _err(string $message = '', int $code = 1): void { | |
if (strlen($message)) | |
fwrite(STDERR, "$message\n"); | |
exit($code); | |
} | |
$opts = array( | |
'socket' => array( | |
'bindto' => "$source_ip:$source_port", | |
), | |
); | |
$context = stream_context_create($opts); | |
$stream = stream_socket_client("udp://{$dest_ip}:$dest_port", $errno, $errstr, 1.0, STREAM_CLIENT_CONNECT, $context); | |
$file = 'multicast_upgrade.img'; | |
if (!file_exists($file)) | |
_err("File '$file' does not exist."); | |
$size = filesize($file); | |
if ($size < 1) | |
_err("No data to send."); | |
$upgrade = str_split(file_get_contents('multicast_upgrade.img'), $block_size); | |
$packets = count($upgrade); | |
var_dump($packets); | |
if ($packets > 65536) | |
_err("File too large."); | |
while(true) { | |
foreach ($upgrade as $packet => $data) { | |
$header = pack("NNNN", ($packet + 1), $block_size, 1, $size); | |
$header .= "bfw-HGW\0\0\0\0\0\0\0\0\0\0\0\0\0"; | |
stream_socket_sendto($stream, $header.$data); | |
usleep(100); | |
// if ($packet > 10) | |
// break 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment