如何用java检查selenium中的ipV6地址?

时间:2015-01-28 05:11:08

标签: java

应用程序显示Ipv6地址。我的selenium项目使用代码检查IP dataValid=IntegerValidator.getInstance().isValid("<<IP>>"); 但这会返回IPV4,因此测试失败。我需要返回IPV6

我尝试了isValidInet6Address(String inet6Address)方法但是

The method isValidInet6Address(String) is undefined for the type InetAddressValidator

错误显示

1 个答案:

答案 0 :(得分:1)

请尝试使用来自httpclient库的InetAddressUtils:

import org.apache.http.conn.util.InetAddressUtils;

public class TestIp {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(InetAddressUtils.isIPv6Address("2001:cdba:0000:0000:0000:0000:3257:9652")); //true
        System.out.println(InetAddressUtils.isIPv6Address("2001:cdba::3257:9652")); //true
        System.out.println(InetAddressUtils.isIPv6Address("2001:cdba:0:0:0:0:3257:9652")); //true
        System.out.println(InetAddressUtils.isIPv6Address("185.23.56.32")); //false
        System.out.println(InetAddressUtils.isIPv4Address("192.168.0.5")); //true
        System.out.println(InetAddressUtils.isIPv4Address("2001:cdba:0:0:0:0:3257:9652")); //false

    }

}