09-04
18

web service :IP查询

String ipprovince = "";
        String ip = "58.214.5.162";
        try {

            // URL url=new
            // URL("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=58.214.5.162");
            URL url = new URL("http://whois.pconline.com.cn/ip.jsp?ip=" + ip);
            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();
            String address = new String(b);

            System.out.println(address);

            if (address.indexOf("省") != -1) {
                ipprovince = address.substring(0, address.indexOf("省") + 1);
                System.out.println("省地址为:" + ipprovince);
            } else if (address.indexOf("区") != -1) {
                ipprovince = address.substring(0, address.indexOf("区") + 1);
                System.out.println("省地址为:" + ipprovince);
            } else {
                ipprovince =

                address.substring(0, address.indexOf("市") + 1);
                System.out.println("省地址为:" + ipprovince);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


[本日志由 blurxx 于 2009-04-18 01:45 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: web service
相关日志:
评论: 0 | 引用: 0 | 查看次数: 429
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭