Java获取本机IP
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface iface = interfaces.nextElement();
if (iface.isLoopback() || !iface.isUp()) {
continue;
}
Enumeration<InetAddress> addresses = iface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
if (addr instanceof Inet6Address) {
continue;
}
ip = addr.getHostAddress();
}
}
} catch (SocketException e) {
LoggerUtils.error(String.format("获取本机IP异常:%s", e.getStackTrace()), null);
ip = "127.0.0.1";
}
Java获取本机IP的更多相关文章
- java获取本机IP地址
转载自:http://blog.csdn.net/thunder09/article/details/5360251 在网上找了几个用java获取本机IP地址的代码,发现都少都有些不完美,自己整理了一 ...
- java获取本机ip(排除虚拟机等一些ip)最终解,总算找到方法了
本文参考https://blog.csdn.net/u011809209/article/details/77236602 本文参考https://blog.csdn.net/yinshuomail/ ...
- 详谈再论JAVA获取本机IP地址
首先,你如果搜索“JAVA获取本机IP地址”,基本上搜到的资料全是无用的.比如这篇:http://www.cnblogs.com/zrui-xyu/p/5039551.html实际上的代码在复杂环境下 ...
- JAVA获取本机IP和Mac地址
在项目中,时常需要获取本机的Ip或是Mac地址,进行身份和权限验证,本文就是通过java代码获取ip和Mac. package com.svse.query;import java.net.In ...
- Java获取本机ip和服务器ip
一.获取服务器IP InetAddress addr = InetAddress.getLocalHost().getHostAddress();//获得本机IP 二.获取客户端本机IP String ...
- java获取本机ip地址(写出来的)
/** * @author 豪弟 * @param request * @return * @throws IOException */ public final static String getI ...
- java获取本机IP地址和MAC地址的方法
// 获取ip地址 public static String getIpAddress() { try { Enumeration<NetworkInterface> allNetInte ...
- Java 获取本机IP
import java.io.*; import java.util.*; import java.net.*; public class GetIP { public static void mai ...
- java 获取本机ip及mac地址
package com.achun.test; import java.net.Inet4Address;import java.net.Inet6Address;import java.net.In ...
随机推荐
- Hyperledger 项目
https://github.com/hyperledger/fabric.githttps://github.com/hyperledger/blockchain-explorer.githttps ...
- python显示多个图表
plt.figure(figsize=(64,64)) 每次都有创建新的,否则会覆盖 plt.subplot(121) plt.imshow(img,'gray') plt.title('origin ...
- Could not execute method of the activity Android
导致此问题的原因有, 一:未注册 如果是 ActivityNotFoundException 的,那说明没在 Manifest.xml 的 application 标签下注册 activity. 二: ...
- .NET零基础入门之01:开篇及CSharp程序、解决方案的结构
一:为什么选择C# 每个人都有梦想,有些人的梦想就是:成为程序员.最课程(www.zuikc.com)的<零基础c#入门>是试图帮助我们实现这个梦想. 也许你要问:我基础很差怎么办?最课程 ...
- 14 道 JavaScript 题?
http://perfectionkills.com/javascript-quiz/ https://www.zhihu.com/question/34079683 著作权归作者所有.商业转载请联系 ...
- C# Process获取当前进程信息
1.获取当前进程信息整理 Process.GetCurrentProcess(),返回当前程序的进程对象. Process cur = Process.GetCurrentProcess(); //当 ...
- 代理服务器polipo;socks5代理转http代理
安装: brew install polipo 使用: To have launchd start polipo now and restart at login: brew services sta ...
- storm的一些相关文章
文章可以看这些: https://www.cnblogs.com/zhaojiankai/p/7257617.html https://blog.csdn.net/wangshuminjava/art ...
- [leetcode]Gray Code @ Python
原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...
- Multiply Strings leetcode java
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...