Java编写IP动态代理

展开全部package com.tan.test;import java.io.BufferedInputStream;import java.io.IOException;import java.net.URL;import java.net.URLConnection;import org.apache.log4j.Logger;public class TestProxyIp{ private static final Logger log = Logger.getLogger(TestProxyIp.class); public static void main(String[] args) throws IOException { System.setProperty("http.maxRedirects", "50"); System.getProperties().setProperty("proxySet", "true"); // 如果不设置,只要代理IP和代理端口正确,此项不设置也可以 String ip = "59.175.192.126"; ip = "221.214.180.130"; ip = "122.224.171.91"; ip = "58.221.213.166"; ip = "202.106.16.36"; ip = "121.8.191.34"; ip = "222.208.242.30"; ip = "219.239.90.85"; ip = "60.31.177.188"; System.getProperties().setProperty("http.proxyHost", ip); System.getProperties().setProperty("http.proxyPort", "3128"); //确定代理是否设置成功 log.info(getHtml("")); //log.info(getHtml("")); } private static String getHtml(String address){ StringBuffer html = new StringBuffer(); String result = null; try{ URL url = new URL(address); URLConnection conn = url.openConnection(); conn.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 7.0; NT 5.1; GTB5; .NET CLR 2.0.50727; CIBA)"); BufferedInputStream in = new BufferedInputStream(conn.getInputStream()); try{ String inputLine; byte[] buf = new byte[4096]; int bytesRead = 0; while (bytesRead >= 0) { inputLine = new String(buf, 0, bytesRead, "UTF-8"); /*if (!"".equals(inputLine)) { System.out.println(inputLine); }*/ html.append(inputLine); bytesRead = in.read(buf); inputLine = null; } buf = null; }finally{ in.close(); conn = null; url = null; } //result = new String(html.toString().trim().getBytes("ISO-8859-1"), "UTF-8").toLowerCase(); //result=new String(html.toString().trim().getBytes("ISO-8859-1"), "GBK"); }catch (Exception e) { e.printStackTrace(); return null; }/*finally{ html = null; }*/ return html.toString(); }}但是找不到有用的动态ip。展开全部您好,提问者: Java中有一个Proxy类,你可以看一下API文档。结合HttpURLConnectin使用,Proxy就是代理类。可以代理Socket、HTTP之类的。展开全部什么意思?获取动态IP?展开全部自己编写多麻烦,而且很多技术,资源,各方面的问题。还不如直接使用一个简单的工具618