Alright well I decided I wanted to widen my learning a bit with java and decided I was going to write a program that had to do with networking side of things.

It took me a little bit of time to come up with something, so I asked my friend and he had an idea for what I should do. That being said, I have a few questions. I'll begin by stating what I want to do and then ask the questions.

The tutorial I have read up on is located at:

http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html

Seems pretty straight forward, which is why I have chosen it.

My friend has a site where he is testing who connects to his site, downloads which files, and at specific times. So he asked if I would write something to help him test it. I agreed as it should be a pretty good learning experience. I have little knowledge on proxies, from what I understand they allow a person to temporarily use another ip address which is what he is looking for. So from what my friend told me, I'm wanting to do the following...

I'm wanting to:

  • URL = textfield1.getText();
  • Open a ProxyList.txt
  • Check for Proxy type and whether its a good or bad proxy
  • If proxy is good, add to an array (so it can be written to a new file later)
  • Change proxy if proxy can't connect after 2 attempts
  • Change proxy if download was successful and download file again from a new proxy till proxyList.txt is empty (about 50 proxies)
  • Use javascript to automatically click download button

Extra options:

  • URL = multiple URLs at a time (perhaps through a list, text file, or arraylist)
  • Different proxy per download
  • Use an int to count unsuccessful attempts
  • Use an int to count successful attempts

A lot of it is covered in the tutorial that I have read, but I'm still looking for advice on how you might go about completing what I'm wanting to do.

* Thus far, I have created a Proxy class that extends ProxySelector (very much like the one in the tutorial/example)

* I have also created the method that handles the bad proxies for two bad connections.

* I have created a nice simlpe GUI for it as well

* I have told him to write the javascript for his site because he is the one who coded it and should know it better than myself. I figure it shouldn't be too hard to implement some javascript in java code. Something like this should work (right?) :

public class RunScriptFile {
  public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    try {
      FileReader reader = new FileReader("yourFile.js");
      engine.eval(reader);
      reader.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

My attempt to make my class pull proxies from proxyList.txt looks like this:

HashMap<SocketAddress, InnerProxy> proxies = new HashMap<SocketAddress, InnerProxy>();

OpenProxy(ProxySelector def) throws FileNotFoundException {
    //Save previous default
    defsel = def;
    
    //Populate the HashMap with proxies from text file
    String myAddress;
    String myPort;
    
    BufferedReader reader = new BufferedReader(new FileReader("myDirectory/proxyList.txt"));

        try {
            while (reader.ready()) {
                String proxyLines = reader.readLine();

                    String[] data = proxyLines.split(":" , 2);
                    myAddress = data[0];
                    myPort = data[1];
                    int myPortNumber = Integer.parseInt(myPort);
                                       
                    InnerProxy i = new InnerProxy(new InetSocketAddress(myAddress , myPortNumber));
                    proxies.put(i.address(), i);
            }
    } catch (Exception e) {
    e.printStackTrace();
    }
}

To do list:

  • Make sure I'm adding proxies from txt to HashMap correctly
  • I need to change proxy after successful attempt
  • Add good proxies to arraylist
  • Multiple URLs/downloads at a time
  • Different proxy per link
  • Account for successful and unsuccessful attempts

If anyone wants to help shed some light on the tasks I would appreciate it. Any pointers, code snippets, etc are welcome. Or if you think you have a better alternative to some of the ways I'm doing things let me know.

I'm surprised there hasn't been a reply yet, perhaps there will be a reply for my next question.

I'm wondering how I would go about opening a url with a different proxy per url?

Hi, I'm not a java expert but I can point an URL where you can download TXT proxy lists for free. Is going to help you in the develop and testing of your project.

By the way, just now that I'm searching for some proxy IPs I see your post, is quite old. Are you still with this develop? May be you have it ready!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.