通过JAVA bean查询ip归属地,身份证号码信息,手机号码归属地
2012-01-09 18:22
786 查看
package test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.regex.Pattern; //获取Ip所在地: http://www.youdao.com/smartresult-xml/search.s?type=ip&q=58.30.32.61<!----> //身份证信息: http://www.youdao.com/smartresult-xml/search.s?type=id&q=232700198910206016<!----> //获取手机所在地: http://www.youdao.com/smartresult-xml/search.s?type=mobile&q=13671151172<!----> public class Test { static Pattern patternLocation = Pattern .compile("<LOCATION>(.+{1,})</LOCATION>"); private static final String IPURL = " http://www.youdao.com/smartresult-xml/search.s?type=ip&q="; private static final String IDURL = " http://www.youdao.com/smartresult-xml/search.s?type=id&q="; private static final String MOBILEURL = " http://www.youdao.com/smartresult-xml/search.s?type=mobile&q="; private static String getLocationByIP(String ip) { String address = ""; try { URL url = new URL(IPURL + ip); address = search(url); } catch (Exception e) { e.printStackTrace(); } address = address.substring(address.indexOf("location") + 9); return address.substring(0, address .indexOf("</location")); } private static String getLocationById(String id) { String address = ""; try { URL url = new URL(IDURL + id); address = search(url); } catch (Exception e) { e.printStackTrace(); } String sex = address.indexOf("<gender>m</gender")>0?"男":"女"; address = address.substring(address.indexOf("location") + 9); String birthday = address.substring(address.indexOf("birthday>")+9,address.indexOf("</bir")); birthday = birthday.substring(0,4)+"年"+birthday.substring(4,6)+"月"+birthday.substring(6,8)+"日"; return "地址:"+address.substring(0, address .indexOf("</location"))+" 性别:"+sex+" 生日:"+birthday; } private static String getLocationByMobile(String mobile) { String address = ""; try { URL url = new URL(MOBILEURL + mobile); address = search(url); } catch (Exception e) { e.printStackTrace(); } address = address.substring(address.indexOf("location") + 9); return "该号码归属地为:"+address.substring(0, address .indexOf("</location")); } private static String search(URL url) throws IOException { String address; HttpURLConnection connect = (HttpURLConnection) url .openConnection(); InputStream is = connect.getInputStream(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buff = new byte[256]; int rc = 0; while ((rc = is.read(buff, 0, 256)) > 0) { outStream.write(buff, 0, rc); } byte[] b = outStream.toByteArray(); //关闭 outStream.close(); is.close(); connect.disconnect(); address = new String(b); return address; } public static void main(String[] args) { //System.out.println(getLocationByIP("221.226.177.158")); System.out.println(getLocationById("321281198710093696")); System.out.println(getLocationByMobile("15895861841")); } }
相关文章推荐
- 新开“翔之光信息查询”身份证、IP、手机号码、周公解梦...
- 查询IP地理位置、身份证所在地、手机归属地的接口
- 查询IP地理位置、身份证所在地、手机归属地的接口
- 一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 借助IP138网站来实现本地系统的IP,身份证号,手机号码查询功能
- IP查询、手机号码归属地、邮政编码、长途电话区号、身份证号码验证专业在线查询
- 一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- IP定位,手机号码及身份证号码查询接口
- 给大家推荐一个查询手机号码归属地和IP物理地址及whois的网站
- PHP一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 给大家推荐一个查询手机号码归属地和IP物理地址及whois的网站
- PHP一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 身份证号码归属地数据库 身份证具体信息查询服务
- 调用webservice查询手机号码归属地信息
- PHP一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 查询IP地理位置、身份证所在地、手机归属地的接口
- 一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 基于Python脚本和聚合数据实现手机号码归属地信息查询
- 一些可以查询IP地理位置、身份证所在地、手机归属地的接口
- 网易有道 IP地址、邮编区号及城市查询、手机号码归属地和身份证 查询接口API