Java 获取本机内外网ip
1. 获取本机内网网ip
public class Test { public static void main(String[] args) throws IOException { System.out.println("内外ip:" + getIp()); System.out.println("外网ip:" + getMyIP()); } /** * 获取本机内网ip * @return * @throws UnknownHostException */ private static String getIp() throws UnknownHostException { String ip = InetAddress.getLocalHost().getHostAddress(); return ip; } /** * 获取本机外网ip * @return */ private static String getMyIP() throws IOException { String url = "http://ip.chinaz.com/getip.aspx"; InputStream is = new URL(url).openStream(); try { BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); StringBuilder sb = new StringBuilder(); int cp; while ((cp = rd.read()) != -1) { sb.append((char) cp); } String msg = sb.toString(); String[] msgs = msg.split(","); String[] ips = msgs[0].split(":"); return ips[1].substring(1, ips[1].length()-1); } finally { is.close(); } } }

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
php获取一些时间实现方法(实践)
php获取一些时间实现方法(实践) 这几天在开发的时候遇到的一些时间上的问题,整理了一下,分享给大家,可以看看,有需要的话可以利用一下。 1.获取上个月第一天及最后一天. echo date('Y-m-01', strtotime('-1 month')); echo "<br/>"; echo date('Y-m-t', strtotime('-1 month')); echo "<br/>"; 上面的方法有些问题,做下修改: 上个月第一天: echo date('Y-m-d', strtotime(date('Y-m-01') . ' -1 month')); // 计算出本月第一天再减一个月 上个月最后一天: echo date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day')); // 计算出本月第一天再减一天 2.获取当月第一天及最后一天. $BeginDate=date('Y-m-01', strtotime(date("Y-m-d"))); echo $BeginDate; echo "<br/&g...
- 下一篇
SpringBoot中搭建Redis缓存
SpringBoot中搭建Redis缓存 (一)SpringBoot中搭建Redis缓存 这篇文章讲述如何在Springboot中搭建redis,参考了很多大神的文章但是运用在我的项目里却不能发挥出来 ,可能框架原因把,因为是在项目搭建完成后再来搭的redis的。搭建redis我感觉我这篇文章比较简单、方便、容易维护话不多说进入正题。 1)、以下链接 是如何在window本地搭建redis进行测试http://www.bieryun.com/3206.html 注意:在导入jedis-2.6.2.jar、spring-data-redis-1.4.2.RELEASE.jar 如果你下载的版本太低可能会提示版本有误(解决方法只要重新下一个高版本就行了),我这个版本应该是没错的。之前 spring-data-redis-1.4.2.RELEASE.jar 我是下载1.0.0所以太低了。 2)在Springboot运用redis方法进行缓存操作 第一步:在pom.xml文件中配置redis [html] view plain copy <!--redis配置--> <dep...
相关文章
文章评论
共有0条评论来说两句吧...