IP地址获取
来源:互联网 发布:java web 进度条实现 编辑:程序博客网 时间:2024/06/04 16:30
package com.xxx.xxx.address;import java.net.Inet4Address;import java.net.InetAddress;import java.net.NetworkInterface;import java.net.SocketException;import java.util.ArrayList;import java.util.Enumeration;import java.util.List;import org.slf4j.Logger;import org.slf4j.LoggerFactory;/** * @Description: IP地址获取 */public class IPAddress {protected static Logger log = LoggerFactory.getLogger(IPAddress.class); public static String find() { List<String> ips = new ArrayList<String>();Enumeration<?> allNetInterfaces = null; try { allNetInterfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { log.error(e.getMessage(),e); } InetAddress ip = null; while (allNetInterfaces.hasMoreElements()) { NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); Enumeration<InetAddress> addresses = netInterface.getInetAddresses(); while (addresses.hasMoreElements()) { ip = (InetAddress) addresses.nextElement(); if (ip != null && ip instanceof Inet4Address && ip.getHostAddress().indexOf(".") != -1) { ips.add(ip.getHostAddress()); } } } if(ips.size()==1){ return ips.get(0); } else{ for (String ipa : ips) {if(!"127.0.0.1".equals(ipa)){return ipa;}} } return MacAddress.find();} }
阅读全文
3 0
- 获取客户端IP地址
- 获取IP地址!
- 获取IP地址
- 获取IP地址
- 获取对方ip地址
- 获取 IP 地址
- 获取客户端ip地址
- asp获取ip地址
- php获取ip 地址
- 获取IP地址
- 获取ip地址
- 获取IP地址
- PHP获取IP地址
- 获取ip地址函数
- 获取ip地址函数
- 获取IP地址
- Java获取IP地址
- 获取IP地址
- 多重背包问题
- 使用adb shell dumpsys检测Android的Activity任务栈
- [python3.6 flask web学习]使用Flask-Mail发送邮件
- 打开hive客户端出现错误create does not exist
- codevs 1004 四子连棋
- IP地址获取
- 2017年8月9日提高组T3 难题
- 高维前缀和
- (吴恩达笔记 1-3)——损失函数及梯度下降
- 写一些HashMap底层结构的理解
- 高压缩空间占用的 Hyper LogLog 算法
- 红黑树结点的删除
- js 简单实现表单数据的增添,单项删改,多项删除,修改以及全选功能
- selenium 下载