重定向网络流量 [英] Redirecting network traffic

查看:62
本文介绍了重定向网络流量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将一些流量重定向出去,所以当被要求使用 1.1.1.1:2222 本地机器时,改为转到 2.2.2.2:3333

I'm trying to redirect some traffic going out, so when asked for 1.1.1.1:2222 local machine instead goes to 2.2.2.2:3333

使用 java 完成此任务的最简单方法是什么?

Whats the easiest way to accomplish this with the use of java ?

最好的问候

Windows 上的主机文件不是!一个选项

hosts file on windows is NOT! an option

ip 1.1.1.1:2222 是一个外部 IP(我不拥有的服务器).因此我无法创建一个简单的套接字服务器来重定向流量.我必须以某种方式改变数据包方向

The ip 1.1.1.1:2222 is an extenal IP(a server i do not own). Therefore i cannot create a simple socket server to redirect the traffic. I have to somehow change the packet direction

另请注意,这是我要重定向的 OUTGOING 部分.一个简单的例子是,如果我要求 www.google.dk,我会得到 facebook

Also note that it is the OUTGOING part i want to redirect. A quick example would be if i ask for www.google.dk i get facebook

这必须从 java 中完成.

This has to be done from java.

推荐答案

你不能在 Java 中做这种事情.实际上,您通常根本无法在用户空间应用程序中执行此操作.

You can't do this kind of thing in Java. Indeed, you generally can't do this thing in user-space applications at all.

如果您使用的是 Linux 平台,您可以潜在地配置 iptables 以拦截指定类型的发往特定 IP 地址/端口的传出数据包,并重写目标 IP 地址.但是,这实际上是系统/网络管理问题,而不是编程问题.

If you are using a Linux platform, you could potentially configure iptables to intercept outgoing packets of a given type that are destined for a particular IP address / port, and rewrite the destination IP address. However, this is really a system / network administration problem, not a programming problem.

您可以想象,如果非特权应用程序可能导致流量被重新路由,您可以做各种令人讨厌的事情.您需要在 Linux 上拥有 root 权限才能更改 iptables 配置.

As you can imagine, there are all sorts of nasty things that you could do if a non-privileged application could cause traffic to be rerouted. You need root priviledge on Linux to change the iptables configs.

这必须从 java 中完成.

This has to be done from java.

好吧,除非您询问应用程序重定向自己的请求,否则无法在 Java 中/从 Java 中完成.

Well, unless you are asking about the application redirecting its own requests, it can't be done in Java / from Java.

(在特殊情况下,您可以通过实现一个自定义套接字工厂来实现此目的,该工厂打开连接到更高级别应用程序代码要求的不同位置.但是,我认为这不是你要求.)

(In the exceptional case, you could potentially do this by implementing a custom socket factory that opens connects to a different place to what the higher levels of your application code is asking for. However, I don't think that is what you are asking for.)

这篇关于重定向网络流量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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