简体   繁体   English

使用Sshuttle时如何在Java套接字中获取正确的客户端IP?

[英]How to get correct client IP in java sockets when using sshuttle?

I am using the utility sshuttle to access internet on my computer. 我正在使用实用程序sshuttle访问计算机上的Internet。

sudo sshuttle --dns -vr user@172.16.30.30 0/0

I have a simple java client server program 我有一个简单的Java客户端服务器程序

Client (My computer running sshuttle) 客户端(我的计算机正在运行)

// client ip is 172.16.23.6
class client {
   public static void main(String args[]) {
     Socket s = new Socket("172.16.30.20",port); // different server
   }
}

The server program, running on 172.16.30.20 在172.16.30.20上运行的服务器程序

class server {
   public static void main(String args[]) {
      ServerSocket s = new ServerSocket(port);
      Socket cl = s.accept();
      System.out.println(cl);
   }
}

When I run the the server and connect the client, the IP address which the socket cl holds is 172.16.30.30 (IP of server to which I did sshuttle) instead of its own IP which is 172.16.23.6 当我运行服务器并连接客户端时,套接字cl拥有的IP地址是172.16.30.30(我进行过shuttle的服务器的IP),而不是它自己的IP 172.16.23.6

When I stop sshuttle, the program works fine and the correct IP address is displayed. 当我停止穿梭时,程序运行正常,并显示正确的IP地址。

I have to run both the programs simultaneously but am unable to do so. 我必须同时运行两个程序,但无法运行。

You are out of the luck. 你真倒霉。 sshuttle is like a proxy. sshuttle就像一个代理。 The sshuttle server creates completely independent TCP connection from 172.16.30.30 to 172.16.30.20 and it copies incoming data from client connection to this connection. 穿梭服务器创建从172.16.30.30到172.16.30.20的完全独立的TCP连接,并将传入的数据从客户端连接复制到此连接。 Your server 172.16.30.20 cannot get the information about the real client address because it is present neither in IP nor in TCP header. 您的服务器172.16.30.20无法获得有关真实客户端地址的信息,因为它既不在IP中也不在TCP标头中。 Your java server is able read sender address from the IP header but it is IP address of host that established the connection and it is 172.16.30.30 (sshuttle server). 您的Java服务器能够从IP标头读取发件人地址,但它是建立连接的主机的IP地址,它是172.16.30.30(班车服务器)。

Application protocols like HTTP have mechanism how to indicate the real client IP address. 诸如HTTP之类的应用协议具有如何指示真实客户端IP地址的机制。 HTTP proxy may add HTTP header X-Forwarded-For and server then may learn the client IP from it. HTTP代理可以添加HTTP标头X-Forwarded-For ,然后服务器可以从中获取客户端IP。 But it is possible only if application proxy adds this information to the forwarded data. 但是只有应用程序代理将此信息添加到转发的数据中才有可能。 sshuttle is application protocol independent so it cannot add such information. sshuttle与应用程序协议无关,因此无法添加此类信息。

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

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