mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
do not fail if netmask is shorter than the IP (e.g. /32 for IPv6)
This commit is contained in:
parent
b0a1afa8f5
commit
34117fc024
@ -32,10 +32,10 @@ public class InetAddressUtils {
|
||||
public static final Pattern HOSTNAME_REGEX = Pattern.compile("\\b((([a-z]|[a-z0-9][a-z0-9\\-]*[a-z0-9])\\.)+([a-z]{2,})|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\b", CASE_INSENSITIVE);
|
||||
|
||||
public static InetAddress startRangeByNetmask(InetAddress address, InetAddress netmask) {
|
||||
byte[] netmaskBytes = netmask.getAddress();
|
||||
byte[] addressBytes = address.getAddress();
|
||||
byte[] netmaskBytes = netmask.getAddress();
|
||||
for (int i = 0; i < addressBytes.length; i++) {
|
||||
addressBytes[i] = (byte) (addressBytes[i] & netmaskBytes[i]);
|
||||
addressBytes[i] = i < netmaskBytes.length ? (byte) (addressBytes[i] & netmaskBytes[i]) : 0;
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(addressBytes);
|
||||
@ -50,7 +50,7 @@ public class InetAddressUtils {
|
||||
byte[] netmaskBytes = netmask.getAddress();
|
||||
byte[] addressBytes = address.getAddress();
|
||||
for (int i = 0; i < addressBytes.length; i++) {
|
||||
addressBytes[i] = (byte) (addressBytes[i] | ~(netmaskBytes[i]));
|
||||
addressBytes[i] = (byte) (i < netmaskBytes.length ? (addressBytes[i] | ~(netmaskBytes[i])) : 255);
|
||||
}
|
||||
try {
|
||||
return InetAddress.getByAddress(addressBytes);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user