Poniżej chciałbym zaprezentować skromne demo:
- funkcję sczytywania listy proxy z pliku do pola tekstowego (tak samo wyglądać będzie pobieranie listy stron)
- funkcję stanowiącą clue projekciku: strzelanie do strony zza proxy.
Do otwierania pliku użyłem jFileChoosera dla poprawienia user experience :)
1: JFileChooser fc = new JFileChooser();
2: int returnVal = fc.showOpenDialog(MainFrame.this);
3: if (returnVal == JFileChooser.APPROVE_OPTION) {
4: try {
5: File file = fc.getSelectedFile();
6:
7: BufferedReader br = null;
8: String sCurrentLine;
9: br = new BufferedReader(new FileReader(file));
10: while ((sCurrentLine = br.readLine()) != null) {
11: jTextArea1.setText(jTextArea1.getText()+"\n"+sCurrentLine);
12: }
13: } catch (FileNotFoundException ex) {
14: Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
15: } catch (IOException ex) {
16: Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
17: }
18: }
Jeśli chodzi o moment samego nabicia samego wejścia. Fajnym rozwiązaniem jest użycie losowania User Agenta w liniach 9-12. User Agent podaje informacje stronie jakiej przeglądarki używa internauta. Dziwnym byłoby gdyby wszyscy nasi użytkownicy używali np. Firefoxa.
1: String [] lines = jTextArea1.getText().split("\n");
2:
3: for (int i =1;i<jTextArea1.getLineCount();i++){
4: String line = lines[i];
5: String [] ip = line.split(":");
6: System.setProperty("http.proxyHost", ip[0]);
7: System.setProperty("http.proxyPort", ip[1]);
8: Random generator = new Random();
9: int r = generator.nextInt(10);
10: if (r%3 == 0 ) System.setProperty("http.agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201");
11: else if (r%3 == 1 ) System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246");
12: else System.setProperty("http.agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
13: URL url;
14: try {
15: url = new URL("http://www.kredytymogilno.jcom.pl/");
16: InputStream in = url.openStream();
17: int chuj = 10;
18: } catch (MalformedURLException ex) {
19: ERRORS++;
20: jLabel8.setText(String.valueOf(ERRORS));
21: continue;
22: } catch (IOException ex) {
23: ERRORS++;
24: jLabel8.setText(String.valueOf(ERRORS));
25: continue;
26: }
27: SUCCESS++;
28: jLabel6.setText(String.valueOf(SUCCESS));
29: System.clearProperty("http.proxyHost");
30: }
Programik przedstawia się na razie mało imponująco:
Jednak jak najbardziej działa :)



Komentarze
Prześlij komentarz