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的更多相关文章

  1. java获取本机IP地址

    转载自:http://blog.csdn.net/thunder09/article/details/5360251 在网上找了几个用java获取本机IP地址的代码,发现都少都有些不完美,自己整理了一 ...

  2. java获取本机ip(排除虚拟机等一些ip)最终解,总算找到方法了

    本文参考https://blog.csdn.net/u011809209/article/details/77236602 本文参考https://blog.csdn.net/yinshuomail/ ...

  3. 详谈再论JAVA获取本机IP地址

    首先,你如果搜索“JAVA获取本机IP地址”,基本上搜到的资料全是无用的.比如这篇:http://www.cnblogs.com/zrui-xyu/p/5039551.html实际上的代码在复杂环境下 ...

  4. JAVA获取本机IP和Mac地址

       在项目中,时常需要获取本机的Ip或是Mac地址,进行身份和权限验证,本文就是通过java代码获取ip和Mac. package com.svse.query;import java.net.In ...

  5. Java获取本机ip和服务器ip

    一.获取服务器IP InetAddress addr = InetAddress.getLocalHost().getHostAddress();//获得本机IP 二.获取客户端本机IP String ...

  6. java获取本机ip地址(写出来的)

    /** * @author 豪弟 * @param request * @return * @throws IOException */ public final static String getI ...

  7. java获取本机IP地址和MAC地址的方法

    // 获取ip地址 public static String getIpAddress() { try { Enumeration<NetworkInterface> allNetInte ...

  8. Java 获取本机IP

    import java.io.*; import java.util.*; import java.net.*; public class GetIP { public static void mai ...

  9. java 获取本机ip及mac地址

    package com.achun.test; import java.net.Inet4Address;import java.net.Inet6Address;import java.net.In ...

随机推荐

  1. Hyperledger 项目

    https://github.com/hyperledger/fabric.githttps://github.com/hyperledger/blockchain-explorer.githttps ...

  2. python显示多个图表

    plt.figure(figsize=(64,64)) 每次都有创建新的,否则会覆盖 plt.subplot(121) plt.imshow(img,'gray') plt.title('origin ...

  3. Could not execute method of the activity Android

    导致此问题的原因有, 一:未注册 如果是 ActivityNotFoundException 的,那说明没在 Manifest.xml 的 application 标签下注册 activity. 二: ...

  4. .NET零基础入门之01:开篇及CSharp程序、解决方案的结构

    一:为什么选择C# 每个人都有梦想,有些人的梦想就是:成为程序员.最课程(www.zuikc.com)的<零基础c#入门>是试图帮助我们实现这个梦想. 也许你要问:我基础很差怎么办?最课程 ...

  5. 14 道 JavaScript 题?

    http://perfectionkills.com/javascript-quiz/ https://www.zhihu.com/question/34079683 著作权归作者所有.商业转载请联系 ...

  6. C# Process获取当前进程信息

    1.获取当前进程信息整理 Process.GetCurrentProcess(),返回当前程序的进程对象. Process cur = Process.GetCurrentProcess(); //当 ...

  7. 代理服务器polipo;socks5代理转http代理

    安装: brew install polipo 使用: To have launchd start polipo now and restart at login: brew services sta ...

  8. storm的一些相关文章

    文章可以看这些: https://www.cnblogs.com/zhaojiankai/p/7257617.html https://blog.csdn.net/wangshuminjava/art ...

  9. [leetcode]Gray Code @ Python

    原题地址:https://oj.leetcode.com/problems/gray-code/ 题意: The gray code is a binary numeral system where ...

  10. Multiply Strings leetcode java

    题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note ...