获取手机号归属地

来源:互联网 发布:java如何使用连接池 编辑:程序博客网 时间:2024/04/28 04:53
由于短信项目的需要,需要知道目前所有手机号的归属地,于是写了一个小程序,通过在线查询,获取手机号的归属地,暂不考虑虚拟运营商和换网手机号。代码如下:
    @Test    public void tt(){        int v_i=20;        for (;v_i<99;v_i++){            get(Convert.toString(v_i));            try {                Thread.sleep(5000);            } catch (InterruptedException e) {                e.printStackTrace();            }finally {            }        }    }    public void get(String v_phone) {        CloseableHttpClient httpclient = HttpClients.createDefault();        String v_url="http://v.showji.com/Locating/showji.com20150108.aspx?m=1"+                 v_phone+ "06331234&output=json&callback=querycallback&timestamp="+                Convert.toString(System.currentTimeMillis());        try {            HttpGet httpget = new HttpGet(v_url);            CloseableHttpResponse response = httpclient.execute(httpget);            try {                HttpEntity entity = response.getEntity();                if (entity != null) {                    String v_path=EntityUtils.toString(entity);                    v_path=v_path.replaceAll("querycallback|;|\\)|\\(","");                    if(v_path.length()<200) {                        JSONObject json = JSON.parseObject(v_path);                        if(!json.getString("Corp").equals("")) {                            System.out.println(v_phone+" : "+json.getString("Mobile") +                                     " : " + json.getString("Corp"));                        }                    }                }            } finally {                response.close();            }        } catch (ClientProtocolException e) {            e.printStackTrace();        } catch (ParseException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        } finally {            try {                httpclient.close();            } catch (IOException e) {                e.printStackTrace();            }        }    }

运行结果如下:

30 : 13006331234 : 中国联通31 : 13106331234 : 中国联通32 : 13206331234 : 中国联通33 : 13306331234 : 中国电信34 : 13406331234 : 中国移动35 : 13506331234 : 中国移动36 : 13606331234 : 中国移动37 : 13706331234 : 中国移动38 : 13806331234 : 中国移动39 : 13906331234 : 中国移动45 : 14506331234 : 中国联通47 : 14706331234 : 中国移动49 : 14906331234 : 中国电信50 : 15006331234 : 中国移动51 : 15106331234 : 中国移动52 : 15206331234 : 中国移动53 : 15306331234 : 中国电信55 : 15506331234 : 中国联通56 : 15606331234 : 中国联通57 : 15706331234 : 中国移动58 : 15806331234 : 中国移动59 : 15906331234 : 中国移动70 : 17006331234 : 中国电信76 : 17606331234 : 中国联通77 : 17706331234 : 中国电信78 : 17806331234 : 中国移动80 : 18006331234 : 中国电信81 : 18106331234 : 中国电信82 : 18206331234 : 中国移动83 : 18306331234 : 中国移动84 : 18406331234 : 中国移动85 : 18506331234 : 中国联通86 : 18606331234 : 中国联通87 : 18706331234 : 中国移动88 : 18806331234 : 中国移动89 : 18906331234 : 中国电信
0 0
原创粉丝点击