java获取本机外网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 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的更多相关文章
- 获取本机外网IP的工具类
ExternalIpAddressFetcher.java package com.tyust.common; import java.io.IOException; import java.io.I ...
- 获取本机外网ip和内网ip
获取本机外网ip //获取本机的公网IP public static string GetIP() { string tempip = ""; try { WebRequest r ...
- cURL 命令获取本机外网 IP
1.1 查询本机外网 IP # curl dhcp.cn 134.175.159.160 1.2 输出格式为 JSON # curl dhcp.cn/?json { "IP": & ...
- 用Linux命令行获取本机外网IP地址
引言:目前获取ip的方法中,ifconfig和ip获取函数得到的都是内网ip.有时候需要获取外网ip,目前通用的做法,是向外部服务器发送请求,解析外部服务器响应,从而得到的自己的外网ip.linux下 ...
- 获取本机外网ip
获取内网ip ifconfig eth0 | grep 'inet'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $2}' 获取公网ip ifc ...
- 获取本机外网IP的方式笔记
1.IP138 网址:http://www.ip138.com/: 分离出的快速查询地址:http://20140507.ip138.com/ic.asp(2014年8月9日有效) 个人经验:百度搜索 ...
- Linux命令行获取本机外网IP地址
问题: 服务器地址为net映射地址,本机ifconfig无法直接获取映射的公网地址. 方法: [root@TiaoBan- nidongde]# curl http://ifconfig.me 50. ...
- 【转】用Linux命令行获取本机外网IP地址
$ curl ifconfig.me $ curl icanhazip.com $ curl ident.me $ curl ipecho.net/plain $ curl whatismyip.ak ...
- 2019-11-17-dotnet-C#-获取本机外网-IP-地址
title author date CreateTime categories dotnet C# 获取本机外网 IP 地址 lindexi 2019-11-17 16:38:10 +0800 201 ...
随机推荐
- [LeetCode] 117. Populating Next Right Pointers in Each Node II 每个节点的右向指针 II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- [LeetCode] 237. Delete Node in a Linked List 删除链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- 用ASP.NET Core 2.1 建立规范的 REST API -- 保护API和其它(总结)
本文介绍如何保护API,无需看前边文章也能明白吧. 预备知识: http://www.cnblogs.com/cgzl/p/9010978.html http://www.cnblogs.com/cg ...
- QT笔记--checkbox
1 复选框 一般用来表示“是/否”.: 2 属性有哪些 如果需要默认选中,那么设置QAbstractButton->checked 3 哪些操作函数 需要判断是否选中.也就是isChecked( ...
- celery无法启动的问题 SyntaxError: invalid syntax
遇到了celery无法启动的问题,报错:SyntaxError: invalid syntax ,这是因为我使用的python版本为最新3.7.3 ,而async已经作为关键字而存在了 在 celer ...
- VMware vSphere6.0 服务器虚拟化部署安装图解(最全,最详细)-搭建的所有步骤
VMware vSphere6.0 服务器虚拟化部署安装图解 一 .VMware vSphere部署的前期规划要点 1.vSphere的优点 (略) 2如何利用现在的设备架构虚拟化环境 在虚拟化过程中 ...
- Redis-缓存有效期与淘汰策略
Redis-缓存有效期与淘汰策略 有效期 节省空间 做到数据弱一致性,有效期失效后,可以保证数据的一致性 过期策略 Redis过期策略通常有三种: 1.定时过期: 每个设置过期时间的Key,系统还要生 ...
- 13 IO流(十)——BufferedReader/BufferedWriter 装饰流
Buffered字符包装流 与Buffered字节装饰流一样,只不过是对字符流进行包装. 需要注意的地方 Buffered字符流在Reader与Writer上有两个新的方法:String readLi ...
- Linux命令xargs的使用
ls | xargs catls | xargs -I {} cat {} 大写I,指定参数的替换符号为{} 自定义
- Typora语法使用说明
目录 文本 标题 超链接 锚点 列表 引用 插入图片 脚注 代码 LaTex公式 插入表情 任务列表 高亮 注脚 文本 代码: *斜体* **粗体** ***斜体加粗体*** ~~删除线~~ < ...