`
jojo_java
  • 浏览: 93462 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

获取IP地址的位置

    博客分类:
  • JAVA
JSP 
阅读更多
public class SearchIP
{

    public static void main (String[] args)
    {
        try
        {
            String arg = "202.96.209.6";
            URL url = new URL("http://whois.pconline.com.cn/ip.jsp?ip=" + arg);
            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();
            System.out.println(new String(b));
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics