📄 ipaddress.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: IPAddress.java
package org.bouncycastle.util;
import java.math.BigInteger;
public class IPAddress
{
private static final BigInteger ZERO = BigInteger.valueOf(0L);
public IPAddress()
{
}
public static boolean isValid(String address)
{
return isValidIPv4(address) || isValidIPv6(address);
}
private static boolean isValidIPv4(String address)
{
if (address.length() == 0)
return false;
int octets = 0;
String temp = (new StringBuilder()).append(address).append(".").toString();
int pos;
for (int start = 0; start < temp.length() && (pos = temp.indexOf('.', start)) > start;)
{
if (octets == 4)
return false;
BigInteger octet;
try
{
octet = new BigInteger(temp.substring(start, pos));
}
catch (NumberFormatException ex)
{
return false;
}
if (octet.compareTo(ZERO) == -1 || octet.compareTo(BigInteger.valueOf(255L)) == 1)
return false;
start = pos + 1;
octets++;
}
return octets == 4;
}
private static boolean isValidIPv6(String address)
{
if (address.length() == 0)
return false;
int octets = 0;
String temp = (new StringBuilder()).append(address).append(":").toString();
int pos;
for (int start = 0; start < temp.length() && (pos = temp.indexOf(':', start)) > start;)
{
if (octets == 8)
return false;
BigInteger octet;
try
{
octet = new BigInteger(temp.substring(start, pos), 16);
}
catch (NumberFormatException ex)
{
return false;
}
if (octet.compareTo(ZERO) == -1 || octet.compareTo(BigInteger.valueOf(65535L)) == 1)
return false;
start = pos + 1;
octets++;
}
return octets == 8;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -