private static String getIpAddress( ){

        String ip = "";
Collection<InetAddress> colInetAddress =getAllHostAddress(); for (InetAddress address : colInetAddress) {
if (!address.isLoopbackAddress() && address.getHostAddress().contains(":") != true)
ip = ip + address.getHostAddress() + ",";
} return ip;
} public static Collection<InetAddress> getAllHostAddress() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
Collection<InetAddress> addresses = new ArrayList<InetAddress>(); while (networkInterfaces.hasMoreElements()) {
NetworkInterface networkInterface = networkInterfaces.nextElement();
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress inetAddress = inetAddresses.nextElement();
addresses.add(inetAddress);
}
} return addresses;
} catch (SocketException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

Java 获取本地IP地址的更多相关文章

  1. Java获取本地IP地址

    import java.net.InetAddress; import java.net.UnknownHostException; public class IpTest { public stat ...

  2. Java获取本地IP地址和主机名

    方式一:通过java.net.InetAddress类获取 public void test1() { try { InetAddress addr = InetAddress.getLocalHos ...

  3. java获取本地IP地址集合包括虚拟机的ip

    public static ArrayList<String> getLocalIpAddr() { ArrayList<String> ipList = new ArrayL ...

  4. 获取本地IP地址信息

    2012-06-05    /// <summary>         /// 获取本地IP地址信息         /// </summary>         void G ...

  5. C# — 动态获取本地IP地址及可用端口

    1.在VS中动态获取本地IP地址,代码如下: 2.获取本机的可用端口以及已使用的端口:

  6. .net获取本地ip地址

    整理代码,.net获取本地ip地址,代码如下: string name = Dns.GetHostName(); IPHostEntry IpEntry = Dns.GetHostEntry(name ...

  7. 获取本地IP地址的vc代码

    作者:朱金灿 来源:http://blog.csdn.net/clever101 获取本地IP地址有两种做法.一种是使用gethostname函数,代码如下: bool CSocketComm::Ge ...

  8. Linux C 网络编程 - 获取本地 ip 地址,mac,通过域名获取对应的 ip

    获取本地 ip 地址,mac,通过域名获取对应的 ip, 是网络编程可能遇到的比较常见的操作了,所以总结如下(封装了3个函数), 直接上代码: #include <stdio.h> #in ...

  9. 获取本地ip地址 C#

    与ipconfig获取的所有信息一致的方法: private void GetIp() { System.Diagnostics.Process cmdp= new System.Diagnostic ...

随机推荐

  1. webRTC实战总结

    前言 前段时间一直在忙一个基于WebRTC的PC和移动端双向视频的项目.第一次接触webRTC,难免遇到了许多问题,比如:webRTC移动端兼容性检测,如何配置MediaStreamConstrain ...

  2. Elasticsearch之pythonAPI简单使用

    elasticsearch自动补全建议功能 数据入库操作 ESmapping要求 PUT music { "mappings": { "_doc" : { &q ...

  3. IOS view的圆角和阴影并存

    记录一下这个简单但又难搞的问题,如何设置 view的圆角和阴影并存 UIView *v=[[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 100 ...

  4. python笔记6:模块

    6. 模块(一个 .py 文件称为一个模块Module) import 语句 类似 _xxx 和 __xxx 这样的 函数/变量 是非公开的(private),不应该被直接引用 函数定义: 外部不需要 ...

  5. EOJ 3.30 B. 蛇形矩阵【找规律/待补】

    [链接]:https://acm.ecnu.edu.cn/contest/59/problem/B/ B. 蛇形矩阵 Time limit per test: 2.0 seconds Memory l ...

  6. TopCoder SRM 682 Div1 Problem 450 SuccessfulMerger (环套树 + 分类讨论)

    题意  给定一个$n$个点$n$条边的无向图,现在要把这个图进行若干次操作,并选择一个点作为首都. 要求除首都外的任意两个点$u$, $v$,从$u$走到$v$必须经过这个首都. 操作为合并两个相邻的 ...

  7. MySQL Workbench关键字转成小写设置

  8. 【spring boot】8.spring boot的日志框架logback使用

    在继续上一篇的Debug调试之后,把spring boot的日志框架使用情况逐步蚕食. 参考:http://tengj.top/2017/04/05/springbo 开篇之前,贴上完整applica ...

  9. 如何部署和运行Scut服务器及游戏:Windows篇

    概述 Scut游戏引擎是一个永久免费的全脚本游戏服务器框架,采用MVC框架设计,简化数据库设计和编码工作:降低对开发人员的开发难度:同时提供了丰富的类库和API接口. 一.    安装环境 必须安装的 ...

  10. PCA原理

    http://blog.csdn.net/shizhixin/article/details/51181379