最近和ip138.com干上了,为了防止别人大批量的刷手机号段,大概2分钟内超过了10次同一ip请求查询就会出现“刷新太频繁<br/>”。my god!这不是逗人玩吗。
只好从wap.ip138.com上抓取手机号了。唉~~
代码如下:
1 public static MobileMarkInfo GetMobileMarkFromWAPIP138(String mobile7){
2
3 // 请求URL
4 String REQUEST_URL = "http://wap.ip138.com/sim.asp";
5 // 请求方法
6 String REQUEST_MOTHOD = "GET";
7 MobileMarkInfo mobileMarkInfo = new MobileMarkInfo();
8 BufferedReader br = null;
9
10 try {
11 HttpURLConnection httpConn = (HttpURLConnection) new URL(REQUEST_URL).openConnection();
12 httpConn.setRequestMethod(REQUEST_MOTHOD);
13 httpConn.setDoOutput(true);
14
15 String requestParameter = "mobile=" + mobile7;
16 httpConn.getOutputStream().write(requestParameter.getBytes());
17 httpConn.getOutputStream().flush();
18 httpConn.getOutputStream().close();
19
20 br = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));
21
22 String lineStr = null;
23
24 while ((lineStr = br.readLine()) != null) {
25 //Log.writeLog(lineStr);
26 lineStr = lineStr.toLowerCase().trim();
27 if(lineStr.equalsIgnoreCase("刷新太频繁<br/>")){
28 return null;
29 }
30 if (lineStr.indexOf("归属地") != -1) {
31
32 lineStr = lineStr.replace("<br/>", "");
33 lineStr = lineStr.replace("归属地:", "");
34
35 String[] areas = lineStr.split(" ", 2);
36 if (areas.length > 1) {
37 mobileMarkInfo.setProvince(areas[0]);
38 if (mobileMarkInfo.getProvince().equalsIgnoreCase("内蒙")) {
39 mobileMarkInfo.setProvince("内蒙古");
40 }
41 mobileMarkInfo.setCity(areas[1]);
42 } else {
43 return null;
44 }
45 }
46 // 获取卡类型
47 if (lineStr.indexOf("卡类型") != -1) {
48 lineStr = lineStr.replace("卡类型:", "");
49 lineStr = lineStr.replace("<br/>", "");
50 mobileMarkInfo.setMobileType(lineStr);
51 }
52 }
53
54 } catch (Exception e) {
55 // e.printStackTrace();
56 mobileMarkInfo = null;
57 Log.writeLog("MobileUtil.GetMobileMarkFromWAPIP138 " + e.getMessage());
58 } finally {
59 if (br != null)
60 try {
61 br.close();
62 } catch (IOException e) {
63 // e.printStackTrace();
64 Log.writeLog("MobileUtil.GetMobileMarkFromWAPIP138 " + e.getMessage());
65 }
66 }
67 return mobileMarkInfo;
68 }
2
3 // 请求URL
4 String REQUEST_URL = "http://wap.ip138.com/sim.asp";
5 // 请求方法
6 String REQUEST_MOTHOD = "GET";
7 MobileMarkInfo mobileMarkInfo = new MobileMarkInfo();
8 BufferedReader br = null;
9
10 try {
11 HttpURLConnection httpConn = (HttpURLConnection) new URL(REQUEST_URL).openConnection();
12 httpConn.setRequestMethod(REQUEST_MOTHOD);
13 httpConn.setDoOutput(true);
14
15 String requestParameter = "mobile=" + mobile7;
16 httpConn.getOutputStream().write(requestParameter.getBytes());
17 httpConn.getOutputStream().flush();
18 httpConn.getOutputStream().close();
19
20 br = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));
21
22 String lineStr = null;
23
24 while ((lineStr = br.readLine()) != null) {
25 //Log.writeLog(lineStr);
26 lineStr = lineStr.toLowerCase().trim();
27 if(lineStr.equalsIgnoreCase("刷新太频繁<br/>")){
28 return null;
29 }
30 if (lineStr.indexOf("归属地") != -1) {
31
32 lineStr = lineStr.replace("<br/>", "");
33 lineStr = lineStr.replace("归属地:", "");
34
35 String[] areas = lineStr.split(" ", 2);
36 if (areas.length > 1) {
37 mobileMarkInfo.setProvince(areas[0]);
38 if (mobileMarkInfo.getProvince().equalsIgnoreCase("内蒙")) {
39 mobileMarkInfo.setProvince("内蒙古");
40 }
41 mobileMarkInfo.setCity(areas[1]);
42 } else {
43 return null;
44 }
45 }
46 // 获取卡类型
47 if (lineStr.indexOf("卡类型") != -1) {
48 lineStr = lineStr.replace("卡类型:", "");
49 lineStr = lineStr.replace("<br/>", "");
50 mobileMarkInfo.setMobileType(lineStr);
51 }
52 }
53
54 } catch (Exception e) {
55 // e.printStackTrace();
56 mobileMarkInfo = null;
57 Log.writeLog("MobileUtil.GetMobileMarkFromWAPIP138 " + e.getMessage());
58 } finally {
59 if (br != null)
60 try {
61 br.close();
62 } catch (IOException e) {
63 // e.printStackTrace();
64 Log.writeLog("MobileUtil.GetMobileMarkFromWAPIP138 " + e.getMessage());
65 }
66 }
67 return mobileMarkInfo;
68 }
其中MobileMarkInfo是我定义的一个类,里面包含手机号段、省份、城市、卡类型这几个信息。