java计算ipv6前缀位数

引入依赖: compile group: 'com.googlecode.java-ipv6', name: 'java-ipv6', version: '0.17'

通过2个ipv6地址, 起止段, 来计算ipv6前缀位数

import com.googlecode.ipv6.IPv6Address;
import com.googlecode.ipv6.IPv6Network;

public class TEST {

	public static void main(String[] args) {
		IPv6Address ip1 = IPv6Address.fromString("240e:00a4:3402:6400:0000:0000:0000:0000");
		IPv6Address ip2 = IPv6Address.fromString("240e:00a4:3402:64ff:ffff:ffff:ffff:ffff");
		int prefixLen = IPv6Network.fromTwoAddresses(ip1, ip2).getNetmask().asPrefixLength();
		System.out.println(prefixLen);
	}
}

 

你可能感兴趣的:(java,ipv6,googlecode)