Java 获取本地IP地址
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地址的更多相关文章
- Java获取本地IP地址
import java.net.InetAddress; import java.net.UnknownHostException; public class IpTest { public stat ...
- Java获取本地IP地址和主机名
方式一:通过java.net.InetAddress类获取 public void test1() { try { InetAddress addr = InetAddress.getLocalHos ...
- java获取本地IP地址集合包括虚拟机的ip
public static ArrayList<String> getLocalIpAddr() { ArrayList<String> ipList = new ArrayL ...
- 获取本地IP地址信息
2012-06-05 /// <summary> /// 获取本地IP地址信息 /// </summary> void G ...
- C# — 动态获取本地IP地址及可用端口
1.在VS中动态获取本地IP地址,代码如下: 2.获取本机的可用端口以及已使用的端口:
- .net获取本地ip地址
整理代码,.net获取本地ip地址,代码如下: string name = Dns.GetHostName(); IPHostEntry IpEntry = Dns.GetHostEntry(name ...
- 获取本地IP地址的vc代码
作者:朱金灿 来源:http://blog.csdn.net/clever101 获取本地IP地址有两种做法.一种是使用gethostname函数,代码如下: bool CSocketComm::Ge ...
- Linux C 网络编程 - 获取本地 ip 地址,mac,通过域名获取对应的 ip
获取本地 ip 地址,mac,通过域名获取对应的 ip, 是网络编程可能遇到的比较常见的操作了,所以总结如下(封装了3个函数), 直接上代码: #include <stdio.h> #in ...
- 获取本地ip地址 C#
与ipconfig获取的所有信息一致的方法: private void GetIp() { System.Diagnostics.Process cmdp= new System.Diagnostic ...
随机推荐
- android中Adapter适配器的讲解
Adapter(适配器的讲解) 适配器就我自己来看,我觉得这是一个非常重要的知识点,Adapter是用来帮助填出数据的中间桥梁,简单点说吧:将各种数据以合适的形式显示在View中给用户看.Adapte ...
- linux解决无法打开资源管理器
前两天升级系统,使用命令pacman -Syyu,大概是使用的是testing缘故,今天发现dolphin无法打开了,使用命令行打开,提示ldmp.so有问题. 解决方法如下: 一,使用命令:pacm ...
- linux内核情景分析之匿名管道
管道的机制由pipe()创建,由pipe()所建立的管道两端都在同一进程.所以必须在fork的配合下,才可以在具有亲缘关系的进程通信 /* * sys_pipe() is the normal C c ...
- hdu 5685(逆元)
Problem A Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- Android判断是否为刘海屏
主要总结主流品牌小米.华为.oppo.vivo的刘海屏判断.在某些特殊页面需要适配刘海屏时,可以用以下方法判断.或者判断屏幕比例是否大于2. /** * 小米刘海屏判断. */ public stat ...
- 牛客网 牛客小白月赛2 A.数字方阵-反魔方阵,梁邱构造法
天坑未补... 水一波博客,再不写博客就咸成鱼干了,只写题不写题解,过一段时间就忘了自己学过什么了. 最近重点就是把开学以来写的题补出来,没学的就滚去学会啊(= =),填一下坑... 从这篇博客开始, ...
- my-> git使用笔记
要在本地新建分支test0227并切换到该分支,运行git checkoutout 并加上-b参数,如: git checkout -b test0227 这相当于执行下面这两条命令: git bra ...
- 都是 htmlspecialchars的错,解决 织梦cms dedecms 标题不能为空 不支持php5.3 php5.4 php5.5版本
article_add.php 101行 $title = htmlspecialchars(cn_substrR($title,$cfg_title_maxlen)); 改成 $title = h ...
- ylb:了解存储过程
ylbtech-SQL Server:SQL Server-了解存储过程 了解存储过程 ylb:了解存储过程 返回顶部 存储过程 2.2.1 主要的编程结构: 变量 数据类型 输入/输出变量 返回值 ...
- 关于异步请求AJAX的具体解释
1,异步请求的方法步骤: 1,推断当前用户支持的浏览器类型 XMLHttpRequest:推断是否支持非IE浏览器,相应的创建方法:xmlhttp = new XMLHttpRequest(); wi ...