简体   繁体   English

netcat,毫秒间隔

[英]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.. 我试图使用netcat每隔几毫秒读取一个文件中的一行,并将其发送到一个端口..

So far I know from netcat documentation that it can insert a time interval between each line sent: 到目前为止,我从netcat文档中了解到它可以在发送的每一行之间插入一个时间间隔:

This is from netcat help manual: 这是来自netcat帮助手册:

-i secs Delay interval for lines sent, ports scanned -i secs发送的线路的延迟间隔,扫描的端口

I tried the following which allows me to insert a minimum of 1 second time interval between each line sent. 我尝试了以下操作,允许我在发送的每一行之间插入至少1秒的时间间隔。

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? 也许通过使用一些实用程序将文件的输入传递给netcat,允许在毫秒级的每个读取之间配置间隔?

Using sleep from GNU coreutils allows to sleep for fractions of a second. 使用GNU coreutils的睡眠可以让你睡几分之一秒。 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". 在每个循环中,变量“line”保存文件的一行,该行通过netcat发送到端口“port”上的主机“host”。 After sending one line, the code waits for 0.001 seconds, asf. 发送一行后,代码等待0.001秒,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. 有关sleep命令等待几分之一秒的能力的更多信息,请参阅“ 如何以bash或ksh睡眠一毫秒 ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM