Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

How can I send data to a UDP port?

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

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

like image 689
700 Software Avatar asked Jun 13 '11 22:06

700 Software


2 Answers

This is a job for netcat.

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.

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

nc -u localhost 2345

Then type the data you want to send.

like image 117
0x90 Avatar answered Sep 19 '22 02:09

0x90


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

Here are my working steps:

Download Swiss File Knife 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\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)

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

like image 36
Mike Fox Avatar answered Sep 22 '22 02:09

Mike Fox