Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.i2p.hack.scripts;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.Properties;
- import java.util.Scanner;
- import java.util.StringTokenizer;
- import org.apache.commons.lang3.StringUtils;
- /**
- * Checker of EEPSites status.
- * @author Adastra.
- * */
- public class SearchEEPSitesI2P implements Runnable {
- /**
- * The path where the file "hosts.txt" is located.
- * */
- private FileInputStream hostsI2P;
- /**
- * The path of the results.
- * */
- private File storeResultsPath;
- /**
- * HTML File of Results by EEPSITE.
- * */
- private FileWriter iframeFile;
- /**
- * CSV File of Results separed with comma.
- * */
- private FileWriter resultsCSVFile;
- /**
- * CSV File of Results separed with comma.
- * */
- private FileWriter eepsitesFailed;
- /**
- * Main Point
- * */
- public static void main(String ... params){
- SearchEEPSitesI2P spider = new SearchEEPSitesI2P();
- spider.readHostsI2P();
- spider.readScanningDir(spider);
- if(spider.hostsI2P == null) {
- return;
- }
- spider.crawlEepsites();
- }
- /**
- * Read the hosts.txt file to parse the EEPSITES registered in the I2P Instance.
- * */
- private void readHostsI2P() {
- String i2pHome="";
- System.out.println("Enter the location of hosts.txt file\n");
- ///home/adastra/.i2p/hosts.txt
- Scanner scanner = new Scanner(System.in);
- i2pHome = scanner.next();
- System.out.println("Hosts File: "+i2pHome);
- try {
- hostsI2P = new FileInputStream(new File(i2pHome));
- } catch(FileNotFoundException file_ex) {
- file_ex.printStackTrace();
- System.out.println("Exception: "+file_ex.getMessage());
- }
- }
- /**
- * Read the Scanning Directory to store all result files.
- * */
- private void readScanningDir(SearchEEPSitesI2P spider) {
- System.out.println("Enter the Directory to Store Files \n");
- Scanner scanner = new Scanner(System.in);
- String dirStore = scanner.next();
- System.out.println("Dir. to store: "+dirStore);
- spider.storeResultsPath = new File(dirStore);
- // /media/Adastra/ScanningResultsI2P
- if(!spider.storeResultsPath.exists()) {
- spider.storeResultsPath.mkdir();
- }
- }
- /**
- * Search the EEPSITES.
- * */
- private void crawlEepsites() {
- try {
- DataInputStream in = new DataInputStream(hostsI2P);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String eepsite;
- while ((eepsite = br.readLine()) != null) {
- Thread crawler = new Thread(this);
- crawler.setName(eepsite);
- crawler.start();
- }
- in.close();
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Read every line in the hosts.txt file an performs the connection with the site.
- * */
- @Override
- public void run() {
- connectEepsite(Thread.currentThread().getName());
- }
- /**
- * Performs the connection with the EEPSITE.
- * @param eepsite EEPSITE to connect.
- * */
- private void connectEepsite(final String eepsite) {
- HttpURLConnection connection = null;
- try {
- StringTokenizer tokenizer = new StringTokenizer(eepsite, "=");
- while(tokenizer.hasMoreElements()) {
- String eepsiteHttp = "http://"+tokenizer.nextToken();
- URL rutaPeticion = new URL(eepsiteHttp);
- Properties sysProps = System.getProperties();
- sysProps.put( "http.proxyHost", "127.0.0.1");
- sysProps.put( "http.proxyPort", "8080" );
- connection = (HttpURLConnection)rutaPeticion.openConnection();
- connection.setRequestProperty("Content-type", "html/text");
- connection.connect();
- if(Math.round((connection.getResponseCode()/100)) == 2) {
- BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String content = "";
- while(br.readLine() != null) {
- content = content+"\n"+br.readLine();
- }
- String iframeName = storeResultsPath+System.getProperty("file.separator")+StringUtils.replace(StringUtils.remove(eepsiteHttp, "http://"), ".i2p", ".html");
- iframeFile = new FileWriter(new File(iframeName));
- BufferedWriter iframeWriter = new BufferedWriter(iframeFile);
- iframeWriter.write(content);
- iframeWriter.close();
- storeInformationEepsites(eepsiteHttp+","+connection.getResponseCode()+","+connection.getResponseMessage()+","+connection.getHeaderField("Server")+","+connection.getHeaderField("Host")+","+connection.getLastModified()+"\n");
- } else {
- storeFailedEepsites(eepsiteHttp+","+connection.getResponseCode()+","+connection.getResponseMessage()+","+connection.getHeaderField("Server")+","+connection.getHeaderField("Host")+","+connection.getLastModified()+"\n");
- }
- }
- }catch(IOException ioException){
- } finally {
- connection.disconnect();
- }
- }
- /**
- * Store Banned information about EEPSITES scanned in the network.
- * */
- private void storeInformationEepsites(String eepsite) {
- try {
- resultsCSVFile = new FileWriter(new File(storeResultsPath+System.getProperty("file.separator")+"resultsCSV.txt"), true);
- BufferedWriter csvWriter = new BufferedWriter(resultsCSVFile);
- csvWriter.write(eepsite);
- csvWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * Store the failed addresses to find EEPSITES.
- * */
- private void storeFailedEepsites(String failed) {
- try {
- eepsitesFailed = new FileWriter(new File(storeResultsPath+System.getProperty("file.separator")+"eepsitesFailed.txt"), true);
- BufferedWriter eepsitesFailedWriter = new BufferedWriter(eepsitesFailed);
- eepsitesFailedWriter.write(failed);
- eepsitesFailedWriter.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement