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 ...
随机推荐
- 完美CSS文档的8个最佳实践
在css的世界,文档没有被得到充分的利用.由于文档对终端用户不可见,因此它的价值常常被忽视.另外,如果你第一次为css编写文档,可能很难确定哪些内容值得记录,以及如何能够高效完成编写. 然而,为C ...
- [MySQL] lock知识梳理
MySQL Lock机制 INDEX: MySQL事务隔离级别 MVCC MySQL Lock类型 MySQL MDL CONTENT: 1. MySQL事务隔离级别 Read Uncommit RU ...
- 记录: 百度webuploader 分片文件上传java服务器端(spring mvc)示例的优化
最近项目上用到文件分片上传,于是找到了百度的一个开源前端控件webuploader. 于是尝试使用. 下载下来后,它提供的服务器端示例代码是php版的,那么Java版的呢? 其实,上传文件都是按照rf ...
- hdu 1005(找循环节)
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 关于centos防火墙
Centos升级到7之后,内置的防火墙已经从iptables变成了firewalld Centos7默认安装了firewalld,如果没有安装的话,可以使用 yum install firewalld ...
- mysql5.6新补充
输入:cd C:\Program Files(x86)\MySQL\MySQL Server 5.6\bin 回车 然后输入:mysqld -install再回车 然后出现 安装成功后,再输入net ...
- CodeForces - 316E3 Summer Homework
Discription By the age of three Smart Beaver mastered all arithmetic operations and got this summer ...
- WebStorm添加多个项目到当前工程目录
File-> Settings -> Directories -> Add Content Root,选择你要加入的Project 点击OK -> Apply -> OK ...
- 列表pagesize修改每页显示的数量失效
◇系统错误修复工具 >> 检测微表正确性 原因是删除一些数据导致记录与实际数据不符 转自:http://bbs.dedecms.com/269491.html
- MySQL主从同步异常问题解决Client requested master to start replication from position > file size
MySQL主从同步异常问题解决Client requested master to start replication from position > file size 一.问题描述 MySQ ...