import org.apache.commons.validator.routines.InetAddressValidator; public class Main { public static void main(String[] args) { String ipAddress = "192.168.1.1"; boolean isValidIPv4 = isValidIPv4(ipAddress); if (isValidIPv4) { System.out.println(ipAddress + " 是一个有效的IPv4地址。"); } else { System.out.println(ipAddress + " 不是一个有效的IPv4地址。"); } } public static boolean isValidIPv4(String ipAddress) { InetAddressValidator validator = InetAddressValidator.getInstance(); return validator.isValidInet4Address(ipAddress); } }
点赞 评论

相关推荐

牛客网
牛客企业服务