如何在软件中将两个物理串行端口相互桥接(并记录穿过的数据)?
基本上,我想将我的计算机放在串行线中间并记录通过它的对话。我正在尝试对这段对话进行逆向工程,并最终模拟对话的一端。
我想要做的粗略图:
通常情况下,我有这个:
__________ __________
| | | |
|Device 1|<======>|Device 2|
|________| |________|
我想这样做:
__________ __________ __________
| | | | | |
|Device 1|<===>|Computer|<===>|Device 2|
|________| |________| |________|
中间的计算机基本上桥接两个设备之间的连接并记录所经过的数据。
使用任何编程语言的答案可能都是有用的。最好我能够在 Windows 或 Linux 上执行此操作(或者如果有人对此问题有通用解决方案)。
Basically, I want to put my computer in the middle of a serial line and record the conversation going across it. I'm trying to reverse engineer this conversation and eventually emulate one end of the conversation.
Rough Diagram of what I'm trying to do:
Normally, I have this:
__________ __________
| | | |
|Device 1|<======>|Device 2|
|________| |________|
I want to do this:
__________ __________ __________
| | | | | |
|Device 1|<===>|Computer|<===>|Device 2|
|________| |________| |________|
With the computer in the middle basically bridging the connection between the two devices and logging the data that goes across.
Answers using any programming language are probably useful. Preferably I would be able to do this on either Windows or Linux (or both if someone has a general solution to this problem).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
那么,一种编程方法就是打开相关设备,然后开始在它们之间转发数据,同时保存到文件中。
大多数任何语言都可以做到。对于 java 和 python 之类的东西有很好的库。
网络上存在多种实现,我通过谷歌搜索找到了一种名为 Telnet Serial Bridge (TSB) 的 Python 实现,它允许您通过以太网桥接连接,并使用 putty 等 telnet 工具进行日志记录。
虽然在过去,我使用过 rxtx.qbang.org 中的 java rxtx 串行通信库 自己做,尽管我怀疑现在有更新的版本,或者可能是 JVM 中内置的东西。
改编自该网站上的示例:
Well, a programmatic way to do it would be to just open the relevant devices, and start forwarding data between them, simultaneously saving to a file.
Most any language can do it. There are nice libraries for things like java and python.
Several implementations exist on the web, I found a python one called Telnet Serial Bridge (TSB) by googling, which would allow you to bridge connections together over ethernet, and log using telnet tools like putty.
Though in the past, I've used the java rxtx serial comm library from rxtx.qbang.org to do it myself, though I suspect there's an updated version now, or maybe something built into the JVM proper.
Adapted from an example on that site:
这是一个小的 python 脚本,用于在两个物理端口之间进行桥接 #!/usr/bin/python
This is a small python script to bridge between two physical ports` #!/usr/bin/python
我可以使用 2 个软件实用程序为 Windows 提供解决方案:
TCP COM Bridge - 可以通过内部 TCP 连接连接 2 个 COM 端口。
高级串行端口监视器 - 可以监视和记录设备之间的对话。
这两个实用程序都在这里:
http://www.aggsoft.com/
I can offer a solution for Windows using 2 software utilities:
TCP COM Bridge - can connect 2 COM port over internal TCP connection.
Advanced Serial Port Monitor - can monitor and record the conversation between devices.
Both utilities are here:
http://www.aggsoft.com/
好吧,我是新手,既然你没有说任何关于你所在平台的信息,我会告诉你我做了什么,但我会提前警告你,这取决于你可能会或可能不会的软件有,这实际上可能根本不是答案,所以请注意讲师。
我的硬件是 MacBook Pro 2.4 GHZ,运行 10.7.5,具有 4GB 内存。
我想做的是从 Wine 中运行的应用程序中读取串行通信信息(因为该应用程序是基于 Windows 的,但我不想使用 Windows(讨厌的便便)。哎呀,我不想 有点奇怪。
也可以使用 mac,但我在虚拟 Linux 方面也没有取得我想要的进展,而且 Ubuntu 在使用一些具体的命令行“schtuff”所需的软件方面 开始。
Parallels Desktop Build 7.0.15107(也许可以在 Virtual Box 中执行此操作,我还没有尝试过)
MultiCom(Martin Louis 的 Mac 免费软件)
http://members.iinet.net.au/~mgl/MartysPlace/MultiCom .html
Ubuntu 8.0.4 Hardy Heron
也许还有其他方法,我必须寻找大约十几种方法来做我想做的事情,但我对输出还不满意,所以这可能是浪费时间。
这个解决方案不使用
说实话,ttysnoop 似乎正是我想要的,socat 似乎是一个遥远的第二个,但对于新手来说有点太多了。
我在其他客户端上遇到的问题(可能是由于我无法弄清楚如何更改有关 com 连接的功能)与阻塞有关。当您监视串行端口时,您想要的是非阻塞连接。所以你只需要听端口的喋喋不休,不要干涉。
客户端建立连接
...它们似乎接管了 com 端口,并且串行端口突然无法供您监控。必须有一种方法来配置它们,所以情况并非如此,但我无法弄清楚。更复杂的是,如果您尝试从 mac 端监控虚拟机中的端口正在做什么,那么仍然有点棘手,或者尝试使用任何方法来克服如何发送数据的“障碍”。相同的数据传输到 2 个串行端口。所以,如果你比我聪明,我邀请你让我变得不那么愚蠢。
在 Mac 端...
设置 - 端口 A
设置 – 端口 B
在虚拟机端 (Parallels Ubuntu 8.0.4)
有关如何操作的更多技术细节,请参阅下文...
Linux
如何显示串口?
dmesg | grep tty
这是您要输入的内容,让嗅探器读取输入,假设您选择主动使用串行连接的串行端口位于另一个套接字端口上,例如 com 1 处的 ttyS0(在此示例中 ttyS1 位于 com 3 处)但你可以通过使用 dmesg | grep tty 来解决这个问题)。
看到信息……
jpnevulator --ascii --timing-print --tty "/dev/ttyS1" –read
不相关的信息,您不应该使用,但引导我理解为什么这是错误的方法......
如何映射Linux 中的 com 端口(当您不担心嗅探端口或使用配置添加串行端口时)?
ln -s /dev/ttyUSB0 com3
撤消此类型
unlink com3
其中 ttyUSB0 是从 dmesg | 找到的端口grp tty 和 com3 是 Wine 所需的端口。这是在 ~/.wine/dosdevices 目录中完成的。
Well, I'm a novice and since you didn't say anything about the platform you’re on, I'll tell you what I did, but I'll warn you in advance, this depends on software you may or may not have and this may not actually be an answer at all, so caveat lector.
My hardware is a MacBook Pro 2.4 GHZ running 10.7.5 with 4GB ram.
What I was trying to do was read the serial comm chatter from an application that was running in Wine (since the application was windows based, but I didn’t want to use windows (icky poo). Heck , I didn’t want to use mac either, but I wasn’t making the headway I wanted to in virtual linux either, add to that Ubuntu is a little weird in the direction they’ve taken with some of the nitty gritty command-line “schtuff”.
Required software to start.
Parallels Desktop Build 7.0.15107 (Might be able to do this in Virtual Box, I haven't tried)
MultiCom (Freeware By Martin Louis for Mac)
http://members.iinet.net.au/~mgl/MartysPlace/MultiCom.html
Ubuntu 8.0.4 Hardy Heron
There maybe other ways, I must have chased down about a dozen ways to do what I wanted to do and I'm not happy yet with the output so this maybe a huge waste of time.
This solution doesn't use
And to be honest, ttysnoop seemed to be exactly what I wanted, socat seemed like a distant 2nd but a little too much for a novice imo.
The problems I ran into with other clients (possibly due to my inability to figure out how to change features about com connections) had to do with blocking. What you want, when you monitor a serial port, is a non-blocking connection. So you just listen to the port chatter and don’t interfere.
If you make a connection to it with clients like...
...it seems that they take over the com port and the serial port is suddenly not available for you to monitor. There must be a way to configure them so this isn’t the case but I couldn’t figure it out. Add to that the complication that if you try to monitor from the mac side what the ports in your virtual machine are doing, it’s a little stickier still or trying to use any way you can to get past this “bump” of how to send the same data to 2 serial ports. So if you're smarter than me, I invite you to please make me less dumb.
On the Mac Side…
Set – Port A
Set – Port B
On Virtual Machine Side (Parallels Ubuntu 8.0.4)
See below for more technical minutia about what to do...
Linux
How to display a serial port?
dmesg | grep tty
This is what you would type in to get the sniffer to read the input assuming the serial port you chose to actively use a serial connection was on the other socketed port, ttyS0 at com 1 for instance (ttyS1 is at com 3 in this but you can figure this out by using dmesg | grep tty).
Seeing the information…
jpnevulator --ascii --timing-print --tty "/dev/ttyS1" –read
Unrelated information that you shouldn’t use, but lead-up to me understanding why it was the wrong way to do this…
How to map a com port in linux (when you’re not worried about sniffing a port or using configure to add the serial ports)?
ln -s /dev/ttyUSB0 com3
To undo this type
unlink com3
Where ttyUSB0 is the port found from dmesg | grp tty and com3 is the desired port for Wine. This is done in the ~/.wine/dosdevices directory.
例如,将电缆从设备的 rx/tx 连接到计算机 com 端口 rx 引脚,并运行终端或串行端口记录器。就这样。
For example take a cable from rx/tx of devices to the computer com port rx pin and run a terminal or serial port logger. Just that.