Netcat的丢弃传入数据包 [英] Netcat drops incoming packets

查看:284
本文介绍了Netcat的丢弃传入数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用bash命令的Ubuntu的机器上,用于控制测量仪器。这两款机器都连接到同一个局域网。测量仪器的TCP端口5025上监听 SCPI命令。标准测试 - 询问仪器的ID - 工作得很好:

I use bash commands on a Ubuntu machine for controlling a measurement instrument. Both machines are connected to the same LAN. The measurement instrument listens on TCP port 5025 for SCPI commands. The standard test - asking for the instrument's ID - works nicely:

mjh@Ubuntu:~$ echo "*IDN?" | netcat 192.168.0.10 5025
Rohde&Schwarz,ZVL-3,12345

但是,当我查询数据(我希望1818 ASCII字符),netcat的只是立即返回:

But when I query for data (I expect 1818 ASCII characters), netcat just returns immediately:

mjh@Ubuntu:~$ echo "TRAC? TRACE1" | netcat 192.168.0.10 5025
mjh@Ubuntu:~$

不过,我可以查询在交互式telnet会话没有问题的数据:

However, I can query for data in a interactive telnet session without problems:

mjh@Ubuntu:~$ telnet 192.168.0.10 5025
Trying 192.168.0.10...
Connected to 192.168.0.10.
Escape character is '^]'.
TRAC? TRACE1
-6.993319702E+001,-6.755982208E+001, ... (1818 chars in total)

我想在脚本中使用这些命令,这就是为什么我要使用的netcat。

I want to use these commands in scripts, which is why I want to use netcat.

我怎样才能找出原因的telnet工程和netcat的不?难道是大包的大小?

How can I find out why telnet works and netcat doesn't? Could it be the large package size?

到目前为止,我(失败)尝试了以下内容:

So far I (unsuccessfully) tried the following:


  • 使用 netcat的-C 为CRLF作为行结束

  • 使用 netcat的-t 更多的telnet兼容性

  • 使用的netcat -u 出于绝望

  • using netcat -C for CRLF as line-ending
  • using netcat -t for more telnet compatibility
  • using netcat -u out of desperation

推荐答案

Netcat的和telnet处理连接不同。

The Root Cause

Netcat and telnet handle the connections differently.

远程登录


  • 建立与仪器的TCP连接

  • 当用户输入数据,将其发送到仪器(在此情况下的TRAC?TRACE1)

  • 从仪器接收数据(多个数据包,如果需要的话)

  • 当用户结束交互式会话,用仪器靠近TCP连接

  • 退出程序

Netcat的


  • 建立与仪器的TCP连接

  • 发送被管道输送到netcat的(在这种情况下,TRAC?TRACE1)的数据

  • 立即的请求的连接将被终止

  • 接收任何数据,仪器挤过

  • 仪器承认并完成TCP连接闭幕后退出程序。

  • Establish TCP connection with instrument
  • Send data that was piped into netcat (in this case "TRAC? TRACE1")
  • Immediately ask for connection to be terminated
  • Receive whatever data the instrument squeezes through
  • Exit program after instrument acknowledges and finishes the closing of the TCP connection.

具体而言,使用的netcat用于查询ID时,仪器立即返回内的 ACK 的ID。但请求数据时,仪器需要更长的时间来获取它,并在仪器的网络适配器关闭可以发送数据之前的连接。

Specifically, when using netcat for querying the ID, the instrument returns the ID immediately within its ACK. But when asking for data, the instrument takes a bit longer to fetch it, and the network adapter in the instrument closes the connection before the data can be sent.

注释建议使用这些工具,但它不是小事,所以我将深入研究的一般程序:

A comment suggested to use these tools, but it's not trivial, so I'll delve into the general procedure:


  • 在Ubuntu的计算机上,安装tcpdump的

  • On the Ubuntu machine, install tcpdump

sudo apt-get install tcpdump


  • 查找您的网络适配器的ID(看一下eth0,eth1的,或任何提醒您的网络适配器。在我来说,我的eth1)。

  • Find the id of your network adapter (Look for eth0, eth1, or anything that reminds you of your network adapter. In my case I got eth1.)

    sudo tcpdump -D
    


  • 捕获所有流量,要么去或来自端口5025(SCPI的端口)。 S0的选项告诉tcpdump程序捕获整个包,而不仅仅是最初的几个字节。 -w选项使tcpdump的原始数据保存到一个文件中。

  • Capture all traffic that either goes to or comes from port 5025 (the SCPI port). The s0 option tells tcpdump to capture the whole package, not just the first few bytes. The -w option makes tcpdump save the raw data to a file.

    sudo tcpdump -i eth1 -s0 port 5025 -w netcat_trac.dump
    


  • 打开第二个终端窗口,执行一个命令的netcat(或telnet会话):

  • Open a second terminal window and execute a netcat command (or telnet session):

     echo "TRAC? TRACE1" | netcat 192.168.0.10 5025
    


  • 在第一个终端窗口,由pressing停止tcpdump的 CTRL + C

    重复这几个不同scenarious,保存输出到不同的使用.dump每次文件。

    Repeat this for several different scenarious, saving the output to different .dump files each time.

    在使用GUI(Windows中,我的情况,而且也适用于Ubuntu的)任何一台PC上安装Wireshark的,并期待在使用.dump文件。

    On any PC with a GUI (Windows, in my case, but also works on Ubuntu), install Wireshark and look at the .dump files.

    讲究系列 SYN (我想建立连接)中, SYN + ACK (我理解你,也要让你的连接), FIN + ACK (我想停下来与你交谈)中捕获的数据包标记。比较,其中这些标志出现在不同的场景的顺序。如果你不知道这意味着,这是一个伟大的介绍。 (如果你想进入粗糙的细节,也注重序列和确认的数字。)

    Pay attention to the series of SYN ("I want to make a connection"), SYN+ACK ("I understand you and also want to make a connection with you"), FIN+ACK(I want to stop talking to you) flags in the capture packets. Compare the order in which these flags appear for the different scenarios. If you have no idea what this mean, this is a great introduction. (If you want to get into gnarly details, also pay attention to the "seq" and "ack" numbers.)

    告诉netcat的关闭使用-q开关连接前等待。

    Tell netcat to wait before closing the connection by using the -q switch.

    echo "TRAC? TRACE1" | netcat -q 1 192.168.0.10 5025
    

    在上面的命令,等待时间为1秒

    In the command above, the wait time is 1 second.

    我相信有更好的解决方案(等待与 PSH 数据包设置一个固定的时间可以是太短或太长,而不是),但这个作品不够好,对我来说。

    I am sure there are better solution (wait for a packet with PSH set instead of a fixed time that may either be too short or too long), but this works well enough for me.

    这篇关于Netcat的丢弃传入数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆