Skip to content

Instantly share code, notes, and snippets.

@talbergs
Forked from miguelmota/nc.php
Last active October 21, 2022 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talbergs/3b3bf0c1e7c5bb358d8e32fbaaba5397 to your computer and use it in GitHub Desktop.
Save talbergs/3b3bf0c1e7c5bb358d8e32fbaaba5397 to your computer and use it in GitHub Desktop.
PHP send message to socket server (netcat)
<?php
$payload = 'hello world';
$stream = stream_socket_client("tcp://127.0.0.1:5555", $errno, $errstr);
if (!$stream) {
echo "{$errno}: {$errstr}\n";
die();
}
fwrite($stream, $payload);
stream_socket_shutdown($stream, STREAM_SHUT_WR);
$contents = stream_get_contents($stream);
fclose($stream);
echo $contents;
?>
nc -k -l 5555
@talbergs
Copy link
Author

FROM alpine
RUN apk add netcat-openbsd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment