Advertisement
Guest User

Untitled

a guest
May 15th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.Random;
  4.  
  5. import javax.net.ssl.*;
  6.  
  7. public class Network {
  8. //Anfang Atribute
  9. private String user = "";
  10. private String pass = "";
  11. private String auth_url = "https://www.die-staemme.de/page/auth";
  12. private String ds = "www.die-staemme.de";
  13. private URL url;
  14. private String lastCSRFToken = "";
  15. //Ende Atribute
  16.  
  17. //Anfang Operationen
  18. public Network() {
  19. }
  20. //Ende Operationen
  21.  
  22. public void setUser(String pUser) {
  23. user = pUser;
  24. }
  25.  
  26. public void setPass(String pPass) {
  27. pass = pPass;
  28. }
  29.  
  30. private String getContentLenght() {
  31. int i = 30 + user.length() + pass.length();
  32. return Integer.toString(i);
  33. }
  34.  
  35. private void setLastCSRFToken(String pToken) {
  36. lastCSRFToken = pToken;
  37. }
  38.  
  39. private String getRandomCSRFToken() {
  40. Random rand = new Random();
  41. String s = "";
  42. int nextHexad;
  43. for (int i = 0; i < 6; i++) {
  44. nextHexad = rand.nextInt();
  45. s += Integer.toHexString(nextHexad);
  46. rand.setSeed(rand.nextLong()-rand.nextInt());
  47. }
  48. setLastCSRFToken(s);
  49. return s;
  50. }
  51.  
  52. private byte[] getAuthParams() {
  53. String s = "username="+user+"&password="+pass+"&remember=1";
  54. try {
  55. return s.getBytes("UTF-8");
  56. } catch (UnsupportedEncodingException e) {
  57. e.printStackTrace();
  58. return "error".getBytes();
  59. }
  60. }
  61.  
  62. public void auth() {
  63. try {
  64. url = new URL(auth_url);
  65. HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
  66. con.setRequestMethod("POST");
  67. con.setRequestProperty("Host", ds);
  68. con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
  69. con.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01");
  70. con.setRequestProperty("Accept-Language", "de-DE,de;q=0.9");
  71. con.setRequestProperty("Accept-Encoding", "gzip, deflate, br");
  72. con.setRequestProperty("Referer", "https://"+ds+"/");
  73. con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  74. con.setRequestProperty("X-CSRF-Token", getRandomCSRFToken());
  75. con.setRequestProperty("X-Requested-With", "XMLHttpRequest");
  76. con.setRequestProperty("Content-Length", getContentLenght());
  77. con.setRequestProperty("Connection", "keep-alive");
  78. con.setDoOutput(true);
  79. con.setDoInput(true);
  80. //writing the params with outputstream, outputstreamwriter & bufferedwriter
  81. // con.getOutputStream().write(getAuthParams());
  82. // con.getOutputStream().flush();
  83. BufferedReader bR = new BufferedReader( new InputStreamReader(con.getInputStream()));
  84. do {
  85. System.out.println(bR.readLine());
  86. } while (bR.ready());
  87. } catch (MalformedURLException e) {
  88. e.printStackTrace();
  89. } catch (IOException e) {
  90. e.printStackTrace();
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement