Java检查IPv4或IPv6地址是否在给定的子网中 [英] Java check if IPv4 or IPv6 address is in a given subnet

查看:754
本文介绍了Java检查IPv4或IPv6地址是否在给定的子网中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查IP地址是否在给定子网中?我能够通过使用Apache Commons SubnetUtils( SubnetUtils.SubnetInfo.isInRange ),但它尚不支持IPv6.

How can I check if an IP address is in a given subnet? I was able to do this by using Apache Commons SubnetUtils (SubnetUtils.SubnetInfo.isInRange) but it does not support IPv6 yet.

推荐答案

edazdarevic的CIDRUtils 支持IPv4和IPv6.该示例未提及boolean isInRange(String ipAddress),但已实现!

edazdarevic's CIDRUtils supports both IPv4 and IPv6. The example does not mention boolean isInRange(String ipAddress), but it is implemented!

另一个选项是 java-ipv6 ,但它不支持IPv4和需要JDK7 .

Another option is java-ipv6, but it does not support IPv4 and requires JDK7.

这篇关于Java检查IPv4或IPv6地址是否在给定的子网中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆