Windows BAT 或 CMD:将一些数据发送到本地主机 udp 端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6336941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:28:04  来源:igfitidea点击:

Windows BAT or CMD: send some data to a localhost udp port

windowsbatch-fileudpcmd

提问by Bryan Field

I have an app that listens on a localhost port. I want a minimal launcher to bring that app's to the front.

我有一个监听本地主机端口的应用程序。我想要一个最小的启动器来将该应用程序带到前面。

My app is in Java. I don't know how to write any exe files, but I can write bat files, and then make a shortcut that launches the bat file without showing the terminal. I would like to have the bat file send some data to a port (preferably UDP so there will not be any stream overhead).

我的应用程序是 Java。我不知道怎么写任何exe文件,但我可以写bat文件,然后制作一个启动bat文件而不显示终端的快捷方式。我想让 bat 文件将一些数据发送到一个端口(最好是 UDP,所以不会有任何流开销)。

How can I send data to a UDP port?

如何将数据发送到 UDP 端口?

One of the things I thought of was nslookup, but that will only connect to port 53 as far as I know.

我想到的一件事是nslookup,但据我所知,它只会连接到端口 53。

This only needs to work on Windows. Would like it to work on XP and up, but I can make a workaround if necessary.

这只需要在 Windows 上工作。希望它适用于 XP 及更高版本,但如有必要,我可以制定解决方法。

回答by 0x90

This is a job for netcat.

这是 netcat 的工作。

http://nc110.sourceforge.net/

http://nc110.sourceforge.net/

After installing you can easily launch it from the command line or write a BAT script to execute it for you. To send date through UDP rather than TCP, use the "-u" switch.

安装后,您可以轻松地从命令行启动它或编写一个 BAT 脚本来为您执行它。要通过 UDP 而不是 TCP 发送数据,请使用“-u”开关。

For example, to send the data to UPD port 2345 on localhost execute:

例如,要将数据发送到本地主机上的 UPD 端口 2345,请执行:

nc -u localhost 2345

Then type the data you want to send.

然后键入要发送的数据。

回答by Mike Fox

I was having quite a few problems sending a UDP command to a Brightsign digital sign with netcat. I ended up using Swiss File Knife. It is possible I had the syntex wrong with my netcat statement. (If anyone could suggest the correct syntax based on my working SFK statement, I would love to know) I just wanted to send a few asci key words to my sign from a batch file. My sign was 192.168.1.22 and listening on port 5000

我在使用 netcat 向 Brightsign 数字标牌发送 UDP 命令时遇到了很多问题。我最终使用了瑞士锉刀。我的 netcat 语句可能有语法错误。(如果有人可以根据我的工作 SFK 语句建议正确的语法,我很想知道)我只是想从批处理文件中向我的签名发送一些 asci 关键字。我的标志是 192.168.1.22 并监听端口 5000

Here are my working steps:

以下是我的工作步骤:

Download Swiss File Knife SKF: http://swissfileknife.sourceforge.net/

下载瑞士锉刀 SKF:http: //swissfileknife.sourceforge.net/

Copied the file to C:\tools and renamed the sfk174.exe file to skf.exe(to make is shorter) and used the bellow syntax to send the UDP command Special

将文件复制到 C:\tools 并将 sfk174.exe 文件重命名为 skf.exe(使其更短)并使用波纹管语法发送 UDP 命令 Special

C:\tools\sfk udpsend 192.168.1.22 5000 “Special” (make sure you put your asci word in quotes. it will work without but not for words with spaces between)

C:\tools\sfk udpsend 192.168.1.22 5000 “Special”(确保你将你的 asci 词放在引号中。它可以不使用但不适用于中间有空格的词)

I put the commands in a batch file and created a windows icon for the customer and they worked great.

我将命令放在一个批处理文件中,并为客户创建了一个 Windows 图标,它们运行良好。

回答by Ehsan Zargar Ershadi

You can send an udp packet like this : c:\nemesis\nemesis.exe udp -P do7on.txt -D 192.168.0.10 -y 1025

您可以像这样发送 udp 数据包: c:\nemesis\nemesis.exe udp -P do7on.txt -D 192.168.0.10 -y 1025

Nemesis : http://nemesis.sourceforge.net/

复仇女神:http: //nemesis.sourceforge.net/