Skip to content

Commit

Permalink
Fixed a problem with error code checking in the proxy tester
Browse files Browse the repository at this point in the history
  • Loading branch information
parislarkins committed Feb 7, 2017
1 parent 0f566c9 commit f88f9b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/pallettown/PTCProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Created by Owner on 25/01/2017.
*/
class PTCProxy {
public class PTCProxy {

private final String ip;
private int usages = 0;
Expand All @@ -16,7 +16,7 @@ class PTCProxy {
public final String auth;


PTCProxy(String ip, String auth){
public PTCProxy(String ip, String auth){
this.ip = ip;
this.auth = auth;
}
Expand Down
26 changes: 10 additions & 16 deletions src/pallettown/ProxyTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,16 @@ public static boolean testProxy(String proxy, String auth) {
return false;
}

int startIndex = responseLine.indexOf(" ") + 1;
int endIndex = responseLine.lastIndexOf(" ");

int responseCode = Integer.parseInt(responseLine.substring(startIndex,endIndex));

switch(responseCode){
case 200:
Log("Proxy " + proxy + " ok!");
valid = true;
break;
case 403:
Log("Proxy " + proxy + " is banned, status code: " + responseLine);
break;
default:
Log("Proxy " + proxy + " gave unexpected response, status code: " + responseLine);
break;

String respCode = responseLine.substring(9);

if(respCode.contains("200 ")){
Log("Proxy " + proxy + " ok!");
valid = true;
}else if(respCode.contains("403 ")){
Log("Proxy " + proxy + " is banned, status code: " + respCode);
}else{
Log("Proxy " + proxy + " gave unexpected response, status code: " + respCode);
}

} catch (IOException e) {
Expand Down
9 changes: 5 additions & 4 deletions src/test/pallettown/ProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
*/
public class ProxyTest implements Runnable {

private static String[] ips = new String[] {
private static final String[] ips = new String[] {
"23.239.219.67:21260",
"104.224.39.45:21279" ,
"138.128.66.121:21260" ,
"38.109.22.101:21324" ,
"45.57.195.248:21235"
};

public static final int THREADS = 1;
private static final int THREADS = 1;
private static final int WORK_ITEMS = 30;


static PTCProxy[] proxies = new PTCProxy[ips.length];
private static final PTCProxy[] proxies = new PTCProxy[ips.length];

int accNum = 0;
private int accNum = 0;

@Test
public void TestProxies(){
Expand Down Expand Up @@ -118,6 +118,7 @@ private static String getProxy() {

System.out.println(" no available proxies, waiting for next available proxy...");
try {
assert shortestWait != null;
System.out.println(" shortest wait time: " + shortestWait.WaitTime());
Thread.sleep(shortestWait.WaitTime());
} catch (InterruptedException e) {
Expand Down

0 comments on commit f88f9b1

Please sign in to comment.