IP 地址批量查询!!在线等,谢谢,解决就结贴! 手头有5314个IP,大概有美国,台湾,香港的,我想知道他们都是哪里的!http://www.ip138.com/只能一个个的查询,太慢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个应该根据IP段进行处理。你应该先知道每个国家和地区的IP段 写个程序,将 5314 个 IP 放在数组内,循环提交给 ip138.com 查,再解析返回的 HTML 就可以了。 import java.io.IOException;import java.util.LinkedHashMap;import java.util.Map;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.methods.PostMethod;public class IP { public static void main(String[] args) throws HttpException, IOException { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("211.100.26.124", ""); map.put("133.13.233.11", ""); map.put("209.131.36.158", ""); map.put("138.175.248.10", ""); map.put("60.12.227.64", ""); map.put("72.21.206.80", ""); map.put("61.152.173.36", ""); long t0 = System.currentTimeMillis(); int i = 0; int size = map.size(); for (Map.Entry<String, String> entry : map.entrySet()) { System.out.printf("[%d/%d] 正在解析 %s", ++i, size, entry.getKey()); String url = "http://www.ip138.com/ips8.asp"; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); method.setParameter("action", "2"); method.setParameter("ip", entry.getKey()); client.executeMethod(method); String response = method.getResponseBodyAsString(); response = new String(response.getBytes("iso-8859-1"), "gb2312"); response = response.substring(response.indexOf("本站主数据:"), response.indexOf("</li></ul>")); map.put(entry.getKey(), response); System.out.println(",解析完成"); method.releaseConnection(); } System.out.printf("解析 5314 个 IP 可能要花:%.2f 小时%n", (System.currentTimeMillis() - t0) * 5314 / (1000.0 * map.size()) / 3600); // 输出 //for (Map.Entry<String, String> entry : map.entrySet()) { // System.out.println(entry.getKey() + " --> " + entry.getValue()); //} System.out.println("OK"); }}以上代码,需要使用 Commons HttpClient 类库http://commons.apache.org/downloads/download_httpclient.cgi以及依赖类库:Commons Logging 和 Commons Codec 类库http://commons.apache.org/downloads/download_logging.cgihttp://commons.apache.org/downloads/download_codec.cgi测试了一下解析 5314 个 IP 大约要花两个小时左右的时间。 js问题,求助 什么时候用ssh框架组合 什么时候用ssi框架组合?各自优势和好处是什么? 关于jsp页面验证和清除session的问题??? jsp怎样做到屏蔽的效果 tomcat 那里下载? 在线请教,一字不明 这句话是什么意思? Tomcat启动出错提示Exception in thread "main" java.lang.NoClassDefFoundError... tomcat 中连接池的问题 新手求助:页面跳转问题 jsp 查询结果不能进行分页,分页只对全部记录进行分页,该如何解决? logic:equal中value的值可以拼接吗?
import java.util.LinkedHashMap;
import java.util.Map;import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;public class IP { public static void main(String[] args) throws HttpException, IOException {
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("211.100.26.124", "");
map.put("133.13.233.11", "");
map.put("209.131.36.158", "");
map.put("138.175.248.10", "");
map.put("60.12.227.64", "");
map.put("72.21.206.80", "");
map.put("61.152.173.36", "");
long t0 = System.currentTimeMillis();
int i = 0;
int size = map.size();
for (Map.Entry<String, String> entry : map.entrySet()) {
System.out.printf("[%d/%d] 正在解析 %s", ++i, size, entry.getKey());
String url = "http://www.ip138.com/ips8.asp";
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(url);
method.setParameter("action", "2");
method.setParameter("ip", entry.getKey());
client.executeMethod(method); String response = method.getResponseBodyAsString();
response = new String(response.getBytes("iso-8859-1"), "gb2312");
response = response.substring(response.indexOf("本站主数据:"), response.indexOf("</li></ul>"));
map.put(entry.getKey(), response);
System.out.println(",解析完成");
method.releaseConnection();
}
System.out.printf("解析 5314 个 IP 可能要花:%.2f 小时%n", (System.currentTimeMillis() - t0) * 5314 / (1000.0 * map.size()) / 3600);
// 输出
//for (Map.Entry<String, String> entry : map.entrySet()) {
// System.out.println(entry.getKey() + " --> " + entry.getValue());
//}
System.out.println("OK");
}
}以上代码,需要使用 Commons HttpClient 类库
http://commons.apache.org/downloads/download_httpclient.cgi以及依赖类库:Commons Logging 和 Commons Codec 类库
http://commons.apache.org/downloads/download_logging.cgi
http://commons.apache.org/downloads/download_codec.cgi测试了一下解析 5314 个 IP 大约要花两个小时左右的时间。