Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- import java.util.zip.CRC32;
- import java.util.zip.Checksum;
- public class rConUDPTool {
- public static void main (String args[]) throws Exception{
- System.out.println("Opening Connection...");
- connect();
- }
- protected static void connect() throws Exception{
- String pass = "xxxxx";
- DatagramSocket clientSocket = new DatagramSocket();
- InetAddress IPAddress = InetAddress.getByName("localhost");
- byte[] sendData = new byte[1024];
- byte[] receiveData = new byte[1024];
- String sentence = "BE";
- sentence += StrToHex("FF00") + pass;
- String header = "BE";
- String hash = StrToHex("FF00") + pass;
- String hashL = getCRC(hash.getBytes());
- hash = StrToHex(hashL);
- char[] HashPreReversed = hash.toCharArray();
- // reverse hash array
- int idx = 0;
- char[] HashReversed = new char[HashPreReversed.length];
- for (int i = HashPreReversed.length - 1; i >= 0; i--){
- HashReversed[idx] = HashPreReversed[i];
- idx++;
- }
- hash = HashReversed.toString();
- header += hash;
- String packet = header + StrToHex("FF00") + pass;
- sendData = packet.getBytes();
- DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 2302);
- clientSocket.send(sendPacket);
- DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
- clientSocket.receive(receivePacket);
- String modifiedSentence = new String(receivePacket.getData());
- System.out.println("FROM SERVER:" + modifiedSentence);
- clientSocket.close();
- }
- protected static String getCRC(byte bs[]){
- byte bytes[] = bs;
- Checksum ckSum = new CRC32();
- ckSum.update(bytes,0,bytes.length);
- String returnValue = Long.toString(ckSum.getValue());
- return returnValue;
- }
- protected static String StrToHex(String str){
- char[] chars = str.toCharArray();
- StringBuffer hex = new StringBuffer();
- for(int i = 0; i <chars.length; i++){
- hex.append(Integer.toHexString((int)chars[i]));
- }
- return hex.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement