Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.InetSocketAddress;
- import java.net.Proxy;
- import java.net.SocketAddress;
- import java.net.URL;
- import java.net.URLConnection;
- public class ProxyTest {
- public static void main(String[] args) {
- FileInputStream fStream = null;
- InputStreamReader isr = null;
- BufferedReader br = null;
- try {
- fStream = new FileInputStream(
- "C:\\Users\\Vlad\\Desktop\\totest.txt");
- isr = new InputStreamReader(fStream);
- br = new BufferedReader(isr);
- String row;
- while ((row = br.readLine()) != null && row != "") {
- testProxy(row.split("\\t")[0],
- Integer.parseInt(row.split("\\t")[1]), true);
- testProxy(row.split("\\t")[0],
- Integer.parseInt(row.split("\\t")[1]), false);
- }
- } catch (Exception ee) {
- ee.printStackTrace();
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (Exception e) {
- }
- } else if (isr != null) {
- try {
- isr.close();
- } catch (Exception e) {
- }
- } else if (fStream != null) {
- try {
- fStream.close();
- } catch (Exception e) {
- }
- }
- }
- }
- public static void testProxy(String hostname, int port, boolean http) {
- SocketAddress addr = new InetSocketAddress(hostname, port);
- Proxy proxy;
- if (http) {
- proxy = new Proxy(Proxy.Type.HTTP, addr);
- } else {
- proxy = new Proxy(Proxy.Type.SOCKS, addr);
- }
- URL url;
- InputStreamReader ir = null;
- BufferedReader br = null;
- try {
- url = new URL("http://www.wimip.fr/");
- URLConnection conn = url.openConnection(proxy);
- ir = new InputStreamReader(conn.getInputStream());
- br = new BufferedReader(ir);
- String inputLine;
- inputLine = br.readLine();
- inputLine = br.readLine();
- inputLine = br.readLine();
- if (inputLine != null) {
- inputLine = inputLine.substring(7, inputLine.length() - 1);
- inputLine = inputLine.split(" ")[0] + " - " + hostname + ":"
- + port;
- if (http) {
- write("HTTP:" + inputLine);
- } else {
- write("SOCKS:" + inputLine);
- }
- }
- } catch (Exception e) {
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (Exception e) {
- }
- } else if (ir != null) {
- try {
- ir.close();
- } catch (Exception e) {
- }
- }
- }
- }
- public static void write(String s) {
- FileOutputStream fStream = null;
- OutputStreamWriter osw = null;
- BufferedWriter bw = null;
- try {
- fStream = new FileOutputStream(
- "C:\\Users\\Vlad\\Desktop\\working.txt", true);
- osw = new OutputStreamWriter(fStream);
- bw = new BufferedWriter(osw);
- bw.write(s);
- bw.newLine();
- } catch (Exception e) {
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (Exception e) {
- }
- } else if (osw != null) {
- try {
- osw.close();
- } catch (Exception e) {
- }
- } else if (fStream != null) {
- try {
- fStream.close();
- } catch (Exception e) {
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement