如何检查IP地址是否来自Java中的特定网络/网络掩码? [英] How to check if an IP address is from a particular network/netmask in Java?

查看:138
本文介绍了如何检查IP地址是否来自Java中的特定网络/网络掩码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定给定的IP地址是否来自某个特殊的网络,以便自动进行身份验证.

I need to determine if given IP address is from some special network in order to authenticate automatically.

推荐答案

Apache Commons Net 具有org.apache.commons.net.util.SubnetUtils似乎可以满足您的需求.看起来您正在执行以下操作:

Apache Commons Net has org.apache.commons.net.util.SubnetUtils that appears to satisfy your needs. It looks like you do something like this:

SubnetInfo subnet = (new SubnetUtils("10.10.10.0", "255.255.255.128")).getInfo();
boolean test = subnet.isInRange("10.10.10.10");

请注意,正如 carson 指出的那样,Apache Commons Net具有

Note, as carson points out, that Apache Commons Net has a bug that prevents it from giving the correct answer in some cases. Carson suggests using the SVN version to avoid this bug.

这篇关于如何检查IP地址是否来自Java中的特定网络/网络掩码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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