使用Dante服务器的Java Socks5客户端和UDP支持

时间:2014-01-27 21:48:07

标签: java android sockets proxy udp

我正在编写SOCKS5客户端

我已经通过TCP进行自动化和udp准备就绪

我已经获得了中继服务器的地址和端口,但我遗漏了udp传输的内容......

   clientSocket = new DatagramSocket();
   IPAddress = InetAddress.getByName(serverHostname); 

   byte[] sendData = new byte[1024]; 
   byte[] receiveData = new byte[1024]; 

   String sentence = "xxx"; 
   sendData = sentence.getBytes();                             

   DatagramPacket sendPacket =  new DatagramPacket(
                                     sendData, 
                                     sendData.length, 
                                     IPAddress, 
                                     sCon.getDstPort()); 

   byte[] addr = sendPacket.getAddress().getAddress();

   byte[]head = new byte[6+addr.length];
   head[0] = (byte) 0x00; //RSV
   head[1] = (byte) 0x00; //RSV
   head[2] = (byte) 0x00; //frag
   head[3] = (byte) 0x01; //Address type
   //Put Address
   System.arraycopy(addr,0,head,4,addr.length);      
   //Put port
   head[head.length - 2] = (byte) (sendPacket.getPort() >> 8);
   head[head.length - 1] = (byte) (sendPacket.getPort());                              


   byte[] buf = new byte[head.length + sendPacket.getLength()];
   byte[] data = sendPacket.getData();
   //Merge 
   System.arraycopy(head,0,buf,0,head.length);
   System.arraycopy(data,0,buf,head.length,sendPacket.getLength());

   DatagramPacket updated = new DatagramPacket(
                                     buf,
                                     buf.length,
                                     relayAddr,
                                     relayPort);                               
   clientSocket.send(updated); 

Socks5 srever - > 192.168.11.52

serverHostname - > 192.168.11.39

客户端IP - > 192.168.11.49

示例情况

Target /192.168.11.39, port 9876
SOCKS5 RelayAddr /192.168.11.52, RelayPort 56945

但丁日志

block(0): udp: expected from 192.168.11.39.148, got it from 192.168.11.49.59124

每次有192.168.11.39 * .148 *,我不明白哪里出错了。 DatagramPacket永远不会到达目标主机

0 个答案:

没有答案