Node.js - 将所有流量从端口 A 转发到端口 B
我正在尝试将所有流量从端口 6999 转发到端口 7000(我知道我可以使用 iptables,但想法是使用 Node.js 进行一些数据包检查)。
这是我到目前为止的代码:
var net=require('net');
var compress=require('./node-compress/compress');
var ip='172.16.1.224';
var ipPort=6999;
var opPort=7000;
var output=net.createServer(function(connOut){
var input=net.createServer(function(connIn){
connIn.pipe(connOut);
});
input.listen(ipPort,ip);
});
output.listen(opPort,ip);
它似乎不起作用。当我在端口 7000 上执行 tcpdump 时,没有任何显示。有人有什么建议吗?
预先非常感谢,
I'm trying to forward all traffic from port 6999 to port 7000 (I know I could use iptables, but the idea is to use Node.js to do some packet inspection).
Here is the code I have sofar:
var net=require('net');
var compress=require('./node-compress/compress');
var ip='172.16.1.224';
var ipPort=6999;
var opPort=7000;
var output=net.createServer(function(connOut){
var input=net.createServer(function(connIn){
connIn.pipe(connOut);
});
input.listen(ipPort,ip);
});
output.listen(opPort,ip);
It just does not seem to work. When I do a tcpdump on port 7000, nothing shows up. Anyone have any suggestions?
Many thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我的做法:
支持从命令行给出“from”和“to”,并支持远程计算机。
(另存为 proxy.js)
从 localhost 转发:9001 ==>本地主机:80
或本地主机:9001 ==> otherhost:80
(这是基于 Andrey 的回答,谢谢!)
Here's my go at it:
Supports giving the "from" and "to" from command line, and supports remote machines.
(save as proxy.js)
To forward from localhost:9001 => localhost:80
Or localhost:9001 => otherhost:80
(This was based on Andrey's answer, thanks!)
您需要在一侧有 createConnection 。这是我用来转发流量的脚本
you need to have createConnection on one side. Here is the script I use to forward traffic
您看过 Node.js 模块 Hoxy 吗?
http://www.youtube.com/watch?v=2YLfBTrVgZU
的快速说明开发者自述文件:
这应该工作得很好,除非您正在寻找较低级别的数据包到包检查。
Have you looked at the Node.js module Hoxy?
http://www.youtube.com/watch?v=2YLfBTrVgZU
Quick description from the developer's README:
This should work pretty well unless you're looking for a lower level, packet to packet inspection of the data.