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] 20. Valid Parentheses 合法括号
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- [LeetCode] 212. Word Search II 词语搜索 II
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word mus ...
- Centos7修改profile错误的解救方案
在改profile的时候,改出问题了,除了cd以外的命令基本都不能用了.使用root用户执行: # export PATH=/usr/bin:/usr/sbin:/bin:/sbin:/usr/X11 ...
- 关于su下bash:xxx :command not found
今天在新建组的时候出了问题: $ su Password: # groupadd prj bash: groupadd :command not found 我就纳闷,明明是在su权限下,怎么还不能使 ...
- vxlan 跨网段虚拟机迁移
一些服务器虚拟化软件可实现在两台虚拟化的物理服务器之间对虚拟机做动态迁移,迁移至另一中心的虚拟机不仅保留原有IP地址,而且还保持迁移前的运行状态(如TCP会话状态),所以必须将涉及虚拟机,迁移的物理服 ...
- Java8 时间日期类操作
Java8 时间日期类操作 Java8的时间类有两个重要的特性 线程安全 不可变类,返回的都是新的对象 显然,该特性解决了原来java.util.Date类与SimpleDateFormat线程不安全 ...
- spring项目配置双数据源读写分离
我们最早做新项目的时候一直想做数据库的读写分离与主从同步,由于一些原因一直没有去做这个事情,这次我们需要配置双数据源的起因是因为我们做了一个新项目用了另一个数据库,需要把这个数据库的数据显示到原来的后 ...
- 使用无图形界面启动Centos
Centos有些时候我们是不需要图形界面的 centos默认安装成功后是有图形界面的,为了减少系统开销,有时候我们需要无图形界面启动linux(centos7) systemctl set-defau ...
- 嵌入式02 STM32 实验02 端口输入输出各4种模式
GPIO(General-purpose input/output 通用目的输入/输出端口) 电压(A模拟量)与电平(D数字量) GPIO 8种工作模式(输入四种.输出四种) 1.GPIO_Mode_ ...
- SQL——BETWEEN操作符
一.BETWEEN操作符的基本用法 BETWEEN操作符用于选取两个值范围内的值. 语法格式如下: SELECT 列名1,列名2... FROM 表名 WHERE 列名 BETWEEN 值1 AND ...