From 2778cf2a16823f9b1153a0549b47f7b503176a17 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 12 九月 2020 18:04:43 +0800 Subject: [PATCH] 爱奇艺正片,搜索引擎 --- src/main/java/com/yeshi/buwan/util/IPUtil.java | 540 ++++++++++++++++++++++++++++++----------------------------- 1 files changed, 276 insertions(+), 264 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/util/IPUtil.java b/src/main/java/com/yeshi/buwan/util/IPUtil.java index 14bc15f..cd8c277 100644 --- a/src/main/java/com/yeshi/buwan/util/IPUtil.java +++ b/src/main/java/com/yeshi/buwan/util/IPUtil.java @@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletRequest; +import com.show.api.ShowApiRequest; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; @@ -18,287 +19,298 @@ import net.sf.json.JSONObject; public class IPUtil { - // http://verx.daili666.com/ip/?tid=558287898012218&num=1&operator=2 - public static void changeIp() { - System.getProperties().setProperty("proxySet", "true"); // 濡傛灉涓嶈缃紝鍙浠g悊IP鍜屼唬鐞嗙鍙f纭�,姝ら」涓嶈缃篃鍙互 - System.getProperties().setProperty("http.proxyHost", "213.85.92.10"); - System.getProperties().setProperty("http.proxyPort", "80"); - LogUtil.i(getHtml("http://www.ip138.com/ip2city.asp")); // 鍒ゆ柇浠g悊鏄惁璁剧疆鎴愬姛 - } + // http://verx.daili666.com/ip/?tid=558287898012218&num=1&operator=2 + public static void changeIp() { + System.getProperties().setProperty("proxySet", "true"); // 濡傛灉涓嶈缃紝鍙浠g悊IP鍜屼唬鐞嗙鍙f纭�,姝ら」涓嶈缃篃鍙互 + System.getProperties().setProperty("http.proxyHost", "213.85.92.10"); + System.getProperties().setProperty("http.proxyPort", "80"); + LogUtil.i(getHtml("http://www.ip138.com/ip2city.asp")); // 鍒ゆ柇浠g悊鏄惁璁剧疆鎴愬姛 + } - 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; Windows 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, "ISO-8859-1"); - 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"), "gb2312").toLowerCase(); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - html = null; - return result; - } + 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; Windows 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, "ISO-8859-1"); + 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"), "gb2312").toLowerCase(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + html = null; + return result; + } - // 娌℃湁鎵惧埌浠g悊IP - // 閲嶅簡 - public static String getDaiLiIP(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod( + // 娌℃湁鎵惧埌浠g悊IP + // 閲嶅簡 + public static String getDaiLiIP(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod( - "http://verx.daili666.com/ip/?tid=559511877530791&num=1&operator=2&filter=on&area=" - + URLEncoder.encode(area, "UTF-8") + ""); - } catch (UnsupportedEncodingException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } + "http://verx.daili666.com/ip/?tid=559511877530791&num=1&operator=2&filter=on&area=" + + URLEncoder.encode(area, "UTF-8") + ""); + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - sendNoticeEmail(result); - LogUtil.i(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + sendNoticeEmail(result); + LogUtil.i(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - public static String getDaiLiIP1(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod( + public static String getDaiLiIP1(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod( - "http://verx.daili666.com/ip/?tid=559186334744019&num=1&area=" + URLEncoder.encode(area, "UTF-8") - + ""); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - sendNoticeEmail(result); - LogUtil.i(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + "http://verx.daili666.com/ip/?tid=559186334744019&num=1&area=" + URLEncoder.encode(area, "UTF-8") + + ""); + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + sendNoticeEmail(result); + LogUtil.i(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - // 鎴愰兘 + // 鎴愰兘 - public static String getDaiLiIP2(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod("http://verx.daili666.com/ip/?tid=558287898012218&num=1&filter=on&area=" - + URLEncoder.encode(area, "UTF-8"));// &area="+ - // URLEncoder.encode(area, - // "UTF-8") + " - } catch (Exception e1) { - e1.printStackTrace(); - } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - sendNoticeEmail(result); - LogUtil.i(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + public static String getDaiLiIP2(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod("http://verx.daili666.com/ip/?tid=558287898012218&num=1&filter=on&area=" + + URLEncoder.encode(area, "UTF-8"));// &area="+ + // URLEncoder.encode(area, + // "UTF-8") + " + } catch (Exception e1) { + e1.printStackTrace(); + } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + sendNoticeEmail(result); + LogUtil.i(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - public static String getDaiLiIP3(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod("http://verx.daili666.com/ip/?tid=557489926231876&num=1&filter=on&area=" - + URLEncoder.encode(area, "UTF-8") + ""); - } catch (UnsupportedEncodingException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - sendNoticeEmail(result); - LogUtil.i(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + public static String getDaiLiIP3(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod("http://verx.daili666.com/ip/?tid=557489926231876&num=1&filter=on&area=" + + URLEncoder.encode(area, "UTF-8") + ""); + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + sendNoticeEmail(result); + LogUtil.i(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - public static String getDaiLiIP4(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod("http://verx.daili666.com/ip/?tid=556436495975069&num=1&area=" - + URLEncoder.encode(area, "UTF-8") + ""); - } catch (UnsupportedEncodingException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - sendNoticeEmail(result); - LogUtil.i(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + public static String getDaiLiIP4(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod("http://verx.daili666.com/ip/?tid=556436495975069&num=1&area=" + + URLEncoder.encode(area, "UTF-8") + ""); + } catch (UnsupportedEncodingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + sendNoticeEmail(result); + LogUtil.i(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - public static String getDaiLiIP5(String area) { - HttpClient client = new HttpClient(); - GetMethod get = null; - try { - get = new GetMethod("http://verx.daili666.com/ip/?tid=559418280288916&num=1&filter=on&area=" - + URLEncoder.encode(area, "UTF-8") + ""); + public static String getDaiLiIP5(String area) { + HttpClient client = new HttpClient(); + GetMethod get = null; + try { + get = new GetMethod("http://verx.daili666.com/ip/?tid=559418280288916&num=1&filter=on&area=" + + URLEncoder.encode(area, "UTF-8") + ""); - } catch (UnsupportedEncodingException e1) { - e1.printStackTrace(); - } - try { - client.executeMethod(get); - String result = get.getResponseBodyAsString(); - LogUtil.i(result); - sendNoticeEmail(result); - if (!result.contains("娌℃湁鎵惧埌")) - return result; - else - return null; - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } + } catch (UnsupportedEncodingException e1) { + e1.printStackTrace(); + } + try { + client.executeMethod(get); + String result = get.getResponseBodyAsString(); + LogUtil.i(result); + sendNoticeEmail(result); + if (!result.contains("娌℃湁鎵惧埌")) + return result; + else + return null; + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } - private static void sendNoticeEmail(String get) { - if (get != null && get.contains("璁㈠崟鍓╀綑鏁伴噺涓嶈冻")) { - /* - * MailSenderUtil.sendEmail("1101184511@qq.com", "绯荤粺鎻愮ず:IP璁㈠崟鍓╀綑鏁伴噺涓嶈冻", - * "IP璁㈠崟鍓╀綑鏁伴噺涓嶈冻锛岃鐧诲綍鍒颁唬鐞�666鍏呭��"); - */ - } - } + private static void sendNoticeEmail(String get) { + if (get != null && get.contains("璁㈠崟鍓╀綑鏁伴噺涓嶈冻")) { + /* + * MailSenderUtil.sendEmail("1101184511@qq.com", "绯荤粺鎻愮ず:IP璁㈠崟鍓╀綑鏁伴噺涓嶈冻", + * "IP璁㈠崟鍓╀綑鏁伴噺涓嶈冻锛岃鐧诲綍鍒颁唬鐞�666鍏呭��"); + */ + } + } - public static String getRemotIP(HttpServletRequest request) { - String ip = request.getHeader("x-forwarded-for"); - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("WL-Proxy-Client-IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("HTTP_CLIENT_IP"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getHeader("HTTP_X_FORWARDED_FOR"); - } - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { - ip = request.getRemoteAddr(); - } - return ip; - } + public static String getRemotIP(HttpServletRequest request) { + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + return ip; + } - public static Map<String, String> getIPInfo(String ip) { - Map<String, String> map = new HashMap<String, String>(); - HttpClient client = new HttpClient(); - GetMethod method = new GetMethod("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip); - try { - client.executeMethod(method); - String result = method.getResponseBodyAsString(); - JSONObject object = JSONObject.fromObject(result); - if (object.optInt("code") == 0) { - map.put("city", object.optJSONObject("data").optString("city")); - map.put("country", object.optJSONObject("data").optString("country")); - return map; - } + public static Map<String, String> getIPInfo(String ip) { + Map<String, String> map = new HashMap<String, String>(); + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip); + try { + client.executeMethod(method); + String result = method.getResponseBodyAsString(); + JSONObject object = JSONObject.fromObject(result); + if (object.optInt("code") == 0) { + map.put("city", object.optJSONObject("data").optString("city")); + map.put("country", object.optJSONObject("data").optString("country")); + return map; + } - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return map; - } + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return map; + } - public static String getIPContry(String ip) { - HttpClient client = new HttpClient(); - GetMethod method = new GetMethod("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip); - try { - client.executeMethod(method); - String result = method.getResponseBodyAsString(); - JSONObject object = JSONObject.fromObject(result); - if (object.optInt("code") == 0) { - return object.optJSONObject("data").optString("country"); - } + public static String getIPContry(String ip) { + String res = new ShowApiRequest("http://route.showapi.com/2152-1", "49053", "983e020ce60042cd95f39b3ebd4b9563") + .addTextPara("ip", ip) + .post(); + JSONObject json = JSONObject.fromObject(res); + if (json.optInt("showapi_res_code") == 0) { + JSONObject body = json.optJSONObject("showapi_res_body"); + if (body != null) + return body.optString("country"); + } + return ""; + } - } catch (HttpException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return ""; - } + public static String getIPProvince(String ip) { + try { + String res = new ShowApiRequest("http://route.showapi.com/2152-1", "49053", "983e020ce60042cd95f39b3ebd4b9563") + .addTextPara("ip", ip) + .post(); + JSONObject json = JSONObject.fromObject(res); + if (json.optInt("showapi_res_code") == 0) { + JSONObject body = json.optJSONObject("showapi_res_body"); + if (body != null) + return body.optString("state"); + } + } catch (Exception e) { + + } + return ""; + } } -- Gitblit v1.8.0