如何使用 NetCat for Windows 将二进制文件发送到 TCP 连接?

发布于 2024-08-17 02:53:17 字数 235 浏览 3 评论 0 原文

如果我想使用 TCP 将二进制文件“binary.bin”(与 NetCat 位于同一目录中)传输到 IP 地址 127.0.0.1 端口 1200,如何使用 NetCat 适用于 Windows?

If I want to transfer a binary file "binary.bin" (located in the same directory as NetCat) to IP address 127.0.0.1 port 1200 using TCP, how do I specify this using NetCat for windows?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的鱼塘能养鲲 2024-08-24 02:53:17

我找到了解决方案。另外

nc 127.0.0.1 1200 < binary.bin

,如果需要保存响应,那么

nc 127.0.0.1 1200 < binary.bin > response.bin

I found the solution. Its

nc 127.0.0.1 1200 < binary.bin

In addition, if the response needs to be saved then

nc 127.0.0.1 1200 < binary.bin > response.bin
岛歌少女 2024-08-24 02:53:17

如果您想将其从 Linux 发行版发送给任何人(包括 Windows PC),您可以执行以下操作:

{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat path/to/your/file/binary.bin ; } | nc -l 1200

然后接收端只需在其 Web 浏览器中浏览到您的 IP 地址并收到下载提示。
不用说,如果您位于路由器后面,则需要转发端口 1200。

If you want to send it from a linux distribution to anybody, including windows PCs you can do something like this:

{ echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat path/to/your/file/binary.bin ; } | nc -l 1200

The receiving end then just needs to browse to your IP Address in his web browser and gets a prompt to download.
Needless to say port 1200 needs to be forwarded if you're behind a router.

垂暮老矣 2024-08-24 02:53:17

我只是想与您分享完整的解决方案,您可以使用该解决方案通过 Netcat 在远程计算机之间的网络公开/提供文件。

我使用这个完美且简单的解决方案以可移植的方式在 Docker 容器之间共享文件,而无需在 Docker 容器中定义 Docker Volume 或安装 ssh。

在源计算机上公开文件的简单 bash 函数:

# ------------------------------------------------------------------------------
# make the file available for another machine via the network
#
# this runs in the background to avoid blocking the main script execution
# ------------------------------------------------------------------------------
function exposeFile() {
    local file port
    file="$1"
    port=1384

    echo "exposing the file for another machine with..."
    echo "   file: $file"
    echo "   port: $port"

    while :
    do
        { echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat "$file" ; } | nc  -l "$port"
    done
}

如果您想多次下载文件,则必须进行无限循环,因为下载后存在 Netcat

从主脚本中调用 bash 方法以在需要时公开文件:

#!/bin/bash
...
exposeFile "path/to/the/file.zip" &

然后您可以使用简单的 wget 将文件下载到源计算机上:

function fileDownload {
    echo "downloading the file..."

    local fileHome file
    fileHome="/download/directory/"
    file="myfile.zip"

    local remoteHost remotePort
    remoteHost="remote-host-or-ip"
    remotePort=1384

    mkdir -p "$fileHome"
    wget -O "$fileHome/$file" "$remoteHost":"$remotePort"
}

我希望这能帮助您节省一些时间;)

I just want to share with you the complete solution that you can use to expose/make available a file via a network between remote computers with Netcat.

I use this perfect and simple solution to share a file between Docker Containers in a portable way without defining Docker Volume or installing ssh in the Docker container.

A simple bash function that exposes the file on the source machine:

# ------------------------------------------------------------------------------
# make the file available for another machine via the network
#
# this runs in the background to avoid blocking the main script execution
# ------------------------------------------------------------------------------
function exposeFile() {
    local file port
    file="$1"
    port=1384

    echo "exposing the file for another machine with..."
    echo "   file: $file"
    echo "   port: $port"

    while :
    do
        { echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat "$file" ; } | nc  -l "$port"
    done
}

The endless loop is necessary if you want to download the file more than one time because after the download Netcat exists.

Call the bash method from your main script to expose the file when you need it:

#!/bin/bash
...
exposeFile "path/to/the/file.zip" &

Then you can use the a simple wget to download the file on the source machine:

function fileDownload {
    echo "downloading the file..."

    local fileHome file
    fileHome="/download/directory/"
    file="myfile.zip"

    local remoteHost remotePort
    remoteHost="remote-host-or-ip"
    remotePort=1384

    mkdir -p "$fileHome"
    wget -O "$fileHome/$file" "$remoteHost":"$remotePort"
}

I hope that this will help you to save some time ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文