import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class MyThread implements Runnable {
private static final String TEST_URL = "http://输入要访问的网站";
private static final int BUFFSIZE = 1024;
private static String getRandomIP() {
return String.format("%d.%d.%d.%d",
(int)(Math.random()*256), (int)(Math.random()*256),
(int)(Math.random()*256), (int)(Math.random()*256));
}
@Override
public void run() {
for (int i = 0; i < 10; i++) {
try {
URL url = new URL(TEST_URL);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-Type", "application/html;charset=UTF-8");
String ip = getRandomIP();
conn.setRequestProperty("X-FORWARDED-FOR", ip);
conn.setRequestProperty("HTTP_CLIENT_IP", ip);
System.out.println("Connection opened: " + ip);
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
byte[] bytes = new byte[BUFFSIZE];
int len = -1;
StringBuffer sb = new StringBuffer();
if (bis != null) {
if ((len = bis.read()) != -1) {
sb.append(new String(bytes, 0, len));
System.out.println(sb.toString());
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class MyThread implements Runnable {
private static final String TEST_URL = "http://输入要访问的网站";
private static final int BUFFSIZE = 1024;
private static String getRandomIP() {
return String.format("%d.%d.%d.%d",
(int)(Math.random()*256), (int)(Math.random()*256),
(int)(Math.random()*256), (int)(Math.random()*256));
}
@Override
public void run() {
for (int i = 0; i < 10; i++) {
try {
URL url = new URL(TEST_URL);
URLConnection conn = url.openConnection();
conn.setRequestProperty("Content-Type", "application/html;charset=UTF-8");
String ip = getRandomIP();
conn.setRequestProperty("X-FORWARDED-FOR", ip);
conn.setRequestProperty("HTTP_CLIENT_IP", ip);
System.out.println("Connection opened: " + ip);
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
byte[] bytes = new byte[BUFFSIZE];
int len = -1;
StringBuffer sb = new StringBuffer();
if (bis != null) {
if ((len = bis.read()) != -1) {
sb.append(new String(bytes, 0, len));
System.out.println(sb.toString());
bis.close();
}
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}