Advertisement
Guest User

Untitled

a guest
Apr 11th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.09 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.zip.CRC32;
  4. import java.util.zip.Checksum;
  5.  
  6. public class rConUDPTool {
  7.  
  8.     public static void main (String args[]) throws Exception{
  9.         System.out.println("Opening Connection...");
  10.        
  11.         connect();
  12.        
  13.     }
  14.    
  15.     protected static void connect() throws Exception{
  16.        
  17.         String pass = "xxxxx";
  18.        
  19.         DatagramSocket clientSocket = new DatagramSocket();
  20.         InetAddress IPAddress = InetAddress.getByName("localhost");
  21.         byte[] sendData = new byte[1024];
  22.         byte[] receiveData = new byte[1024];
  23.        
  24.         String sentence = "BE";
  25.         sentence += StrToHex("FF00") + pass;
  26.        
  27.         String header = "BE";
  28.         String hash = StrToHex("FF00") + pass;
  29.         String hashL = getCRC(hash.getBytes());
  30.        
  31.         hash = StrToHex(hashL);
  32.         char[] HashPreReversed = hash.toCharArray();
  33.        
  34.         // reverse hash array
  35.         int idx = 0;
  36.         char[] HashReversed = new char[HashPreReversed.length];
  37.         for (int i = HashPreReversed.length - 1; i >= 0; i--){
  38.             HashReversed[idx] = HashPreReversed[i];
  39.             idx++;
  40.         }
  41.         hash = HashReversed.toString();
  42.        
  43.         header += hash;
  44.        
  45.         String packet = header + StrToHex("FF00") + pass;
  46.        
  47.         sendData = packet.getBytes();
  48.        
  49.         DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 2302);
  50.         clientSocket.send(sendPacket);
  51.        
  52.         DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
  53.         clientSocket.receive(receivePacket);
  54.        
  55.         String modifiedSentence = new String(receivePacket.getData());
  56.         System.out.println("FROM SERVER:" + modifiedSentence);
  57.         clientSocket.close();
  58.        
  59.        
  60.        
  61.     }
  62.    
  63.    
  64.     protected static String getCRC(byte bs[]){
  65.        
  66.        
  67.         byte bytes[] = bs;
  68.         Checksum ckSum = new CRC32();
  69.        
  70.         ckSum.update(bytes,0,bytes.length);
  71.        
  72.         String returnValue = Long.toString(ckSum.getValue());
  73.        
  74.         return returnValue;
  75.     }
  76.    
  77.     protected static String StrToHex(String str){
  78.         char[] chars = str.toCharArray();
  79.        
  80.         StringBuffer hex = new StringBuffer();
  81.         for(int i = 0; i <chars.length; i++){
  82.             hex.append(Integer.toHexString((int)chars[i]));
  83.         }
  84.        
  85.         return hex.toString();
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement