Java获取本机外网ip地址的方法
来源:互联网 发布:飞控算法 编辑:程序博客网 时间:2024/05/24 16:16
获取本地IP地址的方法
public static String getLocalAddress(){String ip = "";try {ip = InetAddress.getLocalHost().getHostAddress();} catch (UnknownHostException e) {// TODO Auto-generated catch blocke.printStackTrace();}return ip;}
获取外网本机的IP地址的方法
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 blocke.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;
}
参考博客:http://blog.csdn.net/wu_cai_/article/details/52831455
阅读全文
0 0
- Java获取本机外网ip地址的方法
- Java获取本机外网ip地址的方法
- Java获取本机外网ip地址的方法
- java获取本机ip地址方法
- Java获取本机IP地址方法。
- 利用java获取本机IP地址的方法
- 获取本机IP地址的方法:
- java获取本机的ip地址
- java获取本机的ip地址
- Java获取本机的ip地址
- java 获取本机的IP地址
- java获取本机外网IP地址
- java获取本机的IP地址和mac地址
- Java获取本机IP地址(对外的IP地址和局域网的IP地址)
- Java获取本机ip的方法
- 获取本机外网IP地址
- 简单的获取本机ip地址的方法
- 获取外网本机的IP地址的方法
- 互联网大会上的网约车的未来
- html_entity_decode
- python里使用enum库枚举类型时枚举值相同
- 【python运维】系统进程管理方法
- 深度学习课程资源整理
- Java获取本机外网ip地址的方法
- Oracle dbms_output 报ORA-00900错误SP2-0734错误
- SQL
- Java并发学习(十八)-并发工具Exchanger
- openlayer4中使用geojson数据
- 火墙——firewalld and iptables
- 深度学习-卷积理解
- hdoj 1014 Uniform Generator
- 博客 I'am coming