Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.93 KB | None | 0 0
  1. package avitech.resources;
  2.  
  3. import android.util.Log;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.net.InetAddress;
  8. import java.net.InetSocketAddress;
  9. import java.net.Socket;
  10. import java.net.SocketAddress;
  11. import java.util.ArrayList;
  12.  
  13. public class TCPRunnable implements Runnable{
  14. private final String ip;
  15. private final int port;
  16. private final ArrayList<String> commands;
  17.  
  18. //<editor-fold defaultstate="collapsed" desc="Constructors">
  19. @Deprecated
  20. public TCPRunnable(String ip,int port,ArrayList<String> Cmds){
  21. this.ip=ip;
  22. this.port=port;
  23. this.commands = Cmds;
  24. }
  25. public TCPRunnable(String ip,int port,String Cmd){
  26. this.ip=ip;
  27. this.port=port;
  28. this.commands = new ArrayList<String>();
  29. this.commands.add(Cmd);
  30. }
  31. //</editor-fold>
  32.  
  33. //<editor-fold defaultstate="collapsed" desc="Static Properties">
  34.  
  35. //</editor-fold>
  36.  
  37. //<editor-fold defaultstate="collapsed" desc="Instance Properties">
  38.  
  39. //</editor-fold>
  40.  
  41. public void run() {
  42. try {
  43. InetAddress serverAddr = InetAddress.getByName(this.ip);
  44. SocketAddress socketadd= new InetSocketAddress(serverAddr,port);
  45.  
  46. Log.d("TCP","R: Making the socket.");
  47. Socket socket = new Socket();
  48. //new Socket();//
  49. Log.d("TCP","R: Connecting...");
  50. socket.connect(socketadd, 1500);
  51.  
  52. // PrintWriter out = new PrintWriter (new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
  53.  
  54. InputStream socketReader = socket.getInputStream();
  55. OutputStream socketWriter = socket.getOutputStream();
  56. try {
  57. for (int i = 0; i < commands.size();i++){
  58. String Cmd = commands.get(i);
  59. Log.d("TCP","R: Sending: '"+Cmd+"'");
  60. byte [] iByte;
  61. byte[] oByte = new byte[100];//in 32 bit signed integers
  62. int CmdLen = 0;
  63. CmdLen = commands.get(i).length();
  64. oByte[0] = (byte) Integer.parseInt("AF", 16);
  65. oByte[1] = (byte) Integer.parseInt("FA", 16);
  66. oByte[2] = (byte) Integer.parseInt("F0", 16);
  67. oByte[3] = (byte) (255-oByte[2]);
  68. oByte[4] = (byte) (Cmd.length() +2);
  69. oByte[5] = (byte) (255-oByte[4]);
  70. oByte[6] = (byte) Integer.parseInt("07", 16);
  71. iByte = Cmd.getBytes();
  72. System.arraycopy(iByte, 0, oByte, 7, Cmd.length());
  73. oByte[7+CmdLen] = (byte) Integer.parseInt("00",16);
  74. oByte[8+CmdLen] = (byte) Integer.parseInt("00",16);
  75.  
  76. Object [] data = new Object [3];
  77. data[0]=oByte;
  78. data[1]=0;
  79. data[2]=(9 + CmdLen);
  80. //ping(IP,PORT);
  81. //disconnect();
  82. //connect();
  83. socketWriter.write((byte[])data[0],(Integer)data[1],(Integer)data[2]);
  84. socketWriter.flush();
  85. Log.d("TCP","R: Sent.");
  86. //Thread.sleep(500L);
  87. }
  88. }catch (Exception ex){
  89. Log.e("TCP", "S: Sending failed: "+ex);
  90. }finally{
  91.  
  92. socketWriter.flush();
  93. socketWriter.close();
  94. socket.close();
  95. Log.d("TCP","R: Done.");
  96. }
  97.  
  98. } catch (IOException ex) {
  99. Log.e("IOEXCEPTION",""+ex);
  100. }
  101.  
  102.  
  103.  
  104.  
  105. }
  106. //<editor-fold defaultstate="collapsed" desc="Static Methods">
  107.  
  108. //</editor-fold>
  109.  
  110. //<editor-fold defaultstate="collapsed" desc="Instance Methods">
  111.  
  112. //</editor-fold>
  113.  
  114. //<editor-fold defaultstate="collapsed" desc="Accessors">
  115.  
  116. //</editor-fold>
  117.  
  118. }
  119.  
  120. SYN -->
  121. <-- SYN ACK
  122.  
  123. 0.0.0.0 port_to_listen_on_laptop box_ip_address target_box_port
  124.  
  125. rinetd.exe -c rinetd.conf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement