1. public static String getV4IP(){
    String ip = "";
    String chinaz = "http://ip.chinaz.com";

    StringBuilder inputLine = new StringBuilder();
    String read = "";
    URL url = null;
    HttpURLConnection urlConnection = null;
    BufferedReader in = null;
    try {
    url = new URL(chinaz);
    urlConnection = (HttpURLConnection) url.openConnection();
    in = new BufferedReader( new InputStreamReader(urlConnection.getInputStream(),"UTF-8"));
    while((read=in.readLine())!=null){
    inputLine.append(read+"\r\n");
    }
    //System.out.println(inputLine.toString());
    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }finally{
    if(in!=null){
    try {
    in.close();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }

    Pattern p = Pattern.compile("\\<dd class\\=\"fz24\">(.*?)\\<\\/dd>");
    Matcher m = p.matcher(inputLine.toString());
    if(m.find()){
    String ipstr = m.group(1);
    ip = ipstr;
    //System.out.println(ipstr);
    }
    return ip;

java获取本机外网ip的更多相关文章

  1. 获取本机外网IP的工具类

    ExternalIpAddressFetcher.java package com.tyust.common; import java.io.IOException; import java.io.I ...

  2. 获取本机外网ip和内网ip

    获取本机外网ip //获取本机的公网IP public static string GetIP() { string tempip = ""; try { WebRequest r ...

  3. cURL 命令获取本机外网 IP

    1.1 查询本机外网 IP # curl dhcp.cn 134.175.159.160 1.2 输出格式为 JSON # curl dhcp.cn/?json { "IP": & ...

  4. 用Linux命令行获取本机外网IP地址

    引言:目前获取ip的方法中,ifconfig和ip获取函数得到的都是内网ip.有时候需要获取外网ip,目前通用的做法,是向外部服务器发送请求,解析外部服务器响应,从而得到的自己的外网ip.linux下 ...

  5. 获取本机外网ip

    获取内网ip ifconfig eth0 | grep 'inet'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}' 获取公网ip ifc ...

  6. 获取本机外网IP的方式笔记

    1.IP138 网址:http://www.ip138.com/: 分离出的快速查询地址:http://20140507.ip138.com/ic.asp(2014年8月9日有效) 个人经验:百度搜索 ...

  7. Linux命令行获取本机外网IP地址

    问题: 服务器地址为net映射地址,本机ifconfig无法直接获取映射的公网地址. 方法: [root@TiaoBan- nidongde]# curl http://ifconfig.me 50. ...

  8. 【转】用Linux命令行获取本机外网IP地址

    $ curl ifconfig.me $ curl icanhazip.com $ curl ident.me $ curl ipecho.net/plain $ curl whatismyip.ak ...

  9. 2019-11-17-dotnet-C#-获取本机外网-IP-地址

    title author date CreateTime categories dotnet C# 获取本机外网 IP 地址 lindexi 2019-11-17 16:38:10 +0800 201 ...

随机推荐

  1. 相位展开(phase unwrapping)算法研究与实践

    1. 什么是相位展开? 相位展开(Phase Unwrapping)是一个经典的信号处理问题,它指的是从值区间中恢复原始相位值(原因在于:计算相位时,运用反正切函数,则相位图中提取的相位都是包裹在一个 ...

  2. tomcat一闪而过,无法开启

    记事本打开startup.bat,找到最后一句话::end,我们知道end表示结束的意思,:end是一个标记,我们在后面加上一句pause,然后启动该脚本 正常情况下回像下图显示 如果一闪而过的话,可 ...

  3. [LeetCode] 34. Search for a Range 搜索一个范围(Find First and Last Position of Element in Sorted Array)

    原题目:Search for a Range, 现在题目改为: 34. Find First and Last Position of Element in Sorted Array Given an ...

  4. Matlab使用新发现1(小技巧:shell 命令、工程工作目录设置相关)

    最近在调试一个基于Matlab的程序,在偶然间发现了几个比较有趣的技巧,给大家分享一下(很可能是太菜鸟了,没有涉及这方面,大方之家请勿见笑,对您有所帮助请点赞!) 1. Matlab语言是一种解释型语 ...

  5. QT笔记--组合框

    1 数据项 (1)位置 index 第一项位0 (2)文本text 这一项的显示值 (3) 关联数据,每一项可以关联一个数据比如整数或者文本类型数据 2 手工添加项 (1)additem:新数据项附加 ...

  6. SpringBoot+Mybatis+MySql 自动生成代码 自动分页

    一.配置文件 <!-- 通用mapper --> <dependency> <groupId>tk.mybatis</groupId> <arti ...

  7. [03]Go设计模式:工厂模式(Factory Pattern)

    目录 工厂模式 一.简介 二.代码 三.参考资料 工厂模式 一.简介 工厂模式(Factory Pattern)是软件设计中最常用的设计模式之一.这种类型的设计模式属于创建型模式,它提供了一种创建对象 ...

  8. Appcrawler 参数实战经验

    https://testerhome.com/topics/10574 https://yq.aliyun.com/articles/277985 https://github.com/sevenir ...

  9. python的安装与配置

    pyhton的下载与安装 1.python官网地址:https://www.python.org 2.下载 Python 编辑器PyCharm PyCharm 是一款功能强大的 Python 编辑器 ...

  10. liunx mysql数据库目录迁移

    1.查看mysql安装目录 从目录etc/my.cnf中查看安装目录 2.进入mysql目录,停止mysql服务 命令: cd usr/local/mysql 命令:service mysql sto ...