Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

netcat with milliseconds interval

I am trying to use netcat to read a line in a file every few milliseconds, and send it to a port..

So far I know from netcat documentation that it can insert a time interval between each line sent:

This is from netcat help manual:

-i secs Delay interval for lines sent, ports scanned

I tried the following which allows me to insert a minimum of 1 second time interval between each line sent.

nc -q 10 -i 1 -lk 9999 < file_input

I would like to know if there is anyway to reduce this time interval to milliseconds. Maybe by piping input of the file to netcat using some utility that allows for configuring interval between each read in the order of milliseconds?

like image 882
tsar2512 Avatar asked Oct 26 '15 03:10

tsar2512


People also ask

What is the difference between nc and NCAT?

nc and netcat are two names for the same program (typically, one will be a symlink to the other). Though—for plenty of confusion—there are two different implementations of Netcat ("traditional" and "OpenBSD"), and they take different options and have different features. Ncat is the same idea, but from the Nmap project.

What is NCAT used for?

Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project and is the culmination of the currently splintered family of Netcat incarnations.

How do I start Netcat in listen mode?

The command nc –l will put Netcat into server or listening mode, and nc by itself will run Netcat in client mode.


1 Answers

Using sleep from GNU coreutils allows to sleep for fractions of a second. So you can try:

while read -r line ; do echo "$line"; sleep 0.001; done < "/path/to/file" | nc host port

In each loop the variable "line" holds one line of your file, which gets sent through netcat to the host "host" on port "port". After sending one line, the code waits for 0.001 seconds, asf. until there is no more data in the file to send.

See "How do I sleep for a millisecond in bash or ksh" for more information on the ability of the sleep command to wait for fractions of a second.

like image 145
Adrian Zaugg Avatar answered Sep 29 '22 01:09

Adrian Zaugg