@Test public void testLong2Ip() { assertEquals("127.0.0.1", NetUtils.long2Ip(0x7f000001l)); assertEquals("192.168.0.1", NetUtils.long2Ip(0xc0a80001l)); assertEquals("8.8.8.8", NetUtils.long2Ip(0x08080808l)); }
public static String long2Ip(final long ip) { final StringBuilder result = new StringBuilder(15); result.append(ip >> 24 & 0xff).append("."); result.append(ip >> 16 & 0xff).append("."); result.append(ip >> 8 & 0xff).append("."); result.append(ip & 0xff); return result.toString(); }
NetUtils { public static String long2Ip(final long ip) { final StringBuilder result = new StringBuilder(15); result.append(ip >> 24 & 0xff).append("."); result.append(ip >> 16 & 0xff).append("."); result.append(ip >> 8 & 0xff).append("."); result.append(ip & 0xff); return result.toString(); } }
NetUtils { public static String long2Ip(final long ip) { final StringBuilder result = new StringBuilder(15); result.append(ip >> 24 & 0xff).append("."); result.append(ip >> 16 & 0xff).append("."); result.append(ip >> 8 & 0xff).append("."); result.append(ip & 0xff); return result.toString(); }  }
NetUtils { public static String long2Ip(final long ip) { final StringBuilder result = new StringBuilder(15); result.append(ip >> 24 & 0xff).append("."); result.append(ip >> 16 & 0xff).append("."); result.append(ip >> 8 & 0xff).append("."); result.append(ip & 0xff); return result.toString(); }  static long createSequenceBasedMacAddress(final long macAddress); static String getHostName(); static String[] getLocalCidrs(); static String getDefaultHostIp(); static String ipAndNetMaskToCidr(final String ip, final String netmask); static String getCidrNetmask(final long cidrSize); static String getDefaultEthDevice(); static String[] getNetworkParams(final NetworkInterface nic); static boolean isValidIp4(final String ip); static boolean isValidIp4Netmask(final String netmask); static long ip2Long(final String ip); static String long2Ip(final long ip); static String byte2Mac(final byte[] m); static String prefix2Netmask(final short prefix); static InetAddress[] getAllLocalInetAddresses(); static InetAddress[] getInterfaceInetAddresses(final String ifName); static String getLocalIPString(); static InetAddress getLocalInetAddress(); static boolean isLocalAddress(final String strAddress); static boolean isLocalAddress(final InetAddress addr); static String getMacAddress(final InetAddress address); static boolean ipRangesOverlap(final String startIp1, final String endIp1, final String startIp2, final String endIp2); static String[] getNicParams(final String nicName); static boolean isSiteLocalAddress(final String ipAddress); static boolean validIpRange(final String startIP, final String endIP); static boolean validIpRange(final String ipRange); static boolean is31PrefixCidr(final String cidr); static boolean isValidIp4Cidr(final String cidr); static SortedSet<Long> getAllIpsFromCidr(final String cidr, final Set<Long> usedIps); static SortedSet<Long> getAllIpsFromCidr(final String cidr_ip, final long size, final Set<Long> usedIps); static SortedSet<Long> listIp2LongList(final List<String> ipStringList); static long getRandomIpFromCidr(final String startIp, final int size, final SortedSet<Long> avoid); static long getRandomIpFromCidr(final long cidr, final int size, final SortedSet<Long> avoid); static boolean sameSubnet(final String ip1, final String ip2, final String netmask); static String getSubNet(final String ip, final String netmask); static boolean sameSubnetCIDR(final String ip1, final String ip2, final long cidrSize); static String getCidrSubNet(final String ip, final long cidrSize); static Pair<String, Integer> getCidr(final String cidr); static SupersetOrSubset isNetworkASubsetOrSupersetOfNetworkB(final String cidrA, final String cidrB); static Long[] cidrToLong(final String cidr); static String getCidrSubNet(final String cidr); static String getCidrNetmask(final String cidr); static String getCidrHostAddress(final String cidr); static String getCidrHostAddress6(final String cidrv6); static String cidr2Netmask(final String cidr); static boolean isValidPort(final int p); static boolean isValidPort(final String p); static boolean isValidAlgorithm(final String p); static String getLinkLocalNetMask(); static String[] getLinkLocalIPRange(final int size); static String[] getIpRangeFromCidr(final String cidr, final long size); static String getLinkLocalGateway(); static String getLinkLocalIpEnd(); static String getLinkLocalCIDR(); static String getIpRangeEndIpFromCidr(final String cidr, final long size); static String portRangeToString(final int portRange[]); static boolean verifyDomainName(final String domainName); static boolean verifyDomainNameLabel(final String hostName, final boolean isHostName); static String getDhcpRange(final String cidr); static String getIpRangeStartIpFromCidr(final String cidr, final long size); static boolean isSameIpRange(final String cidrA, final String cidrB); static boolean verifyInstanceName(final String instanceName); static boolean isNetworksOverlap(final String cidrA, final String cidrB); static boolean isValidS2SVpnPolicy(final String policyType, final String policys); static boolean isValidCidrList(final String cidrList); static boolean validateGuestCidrList(final String guestCidrList); static boolean validateGuestCidr(final String cidr); static boolean isValidMac(final String macAddr); static boolean isUnicastMac(final String macAddr); static boolean isNetworkAWithinNetworkB(final String cidrA, final String cidrB); static boolean validateIcmpType(final long icmpType); static boolean validateIcmpCode(final long icmpCode); static boolean isValidIp6(final String ip); static boolean isValidIp6Cidr(final String ip6Cidr); static int getIp6CidrSize(final String ip6Cidr); static String getIp6FromRange(final String ip6Range); static List<String> getAllIpsFromRangeList(final String excludedIpsExpression); static List<String> getAllIpsFromRange(final String range); static Boolean isIpRangeListInCidr(final String ipRangeListExpression, final String cidr); static BigInteger countIp6InRange(final String ip6Range); static boolean isIp6InRange(final String ip6, final String ip6Range); static boolean isIp6InNetwork(final IPv6Address ip, final IPv6Network network); static boolean isIp6InNetwork(final String ip6, final String ip6Cidr); static boolean isIp6InNetwork(final String ip6, final String ip6Cidr, final Boolean inclusiveHostCount); static boolean isIp6RangeOverlap(final String ipRange1, final String ipRange2); static String getNextIp6InRange(final String currentIp, final String ipRange); static String standardizeIp6Address(final String ip6Addr); static String standardizeIp6Cidr(final String ip6Cidr); static String standardizeMacAddress(final String macAddr); static boolean isValidVlan(String vlan); static boolean isSameIsolationId(String one, String other); static URI generateUriForPvlan(final String primaryVlan, final String isolatedPvlan); static String getPrimaryPvlanFromUri(final URI uri); static String getIsolatedPvlanFromUri(final URI uri); static String generateMacOnIncrease(final String baseMac, final long l); static long mac2Long(final String macAddress); static String long2Mac(final long macAddress); static boolean isIpWithtInCidrRange(final String ipAddress, final String cidr); static boolean isIpInCidrList(final InetAddress address, final String[] cidrlist); static Boolean IsIpEqualToNetworkOrBroadCastIp(final String requestedIp, final String cidr, final long size); static boolean isNetworkorBroadcastIP(final String ip, final String netmask); static String getCidrFromGatewayAndNetmask(final String gatewayStr, final String netmaskStr); static long getCidrSize(final String netmask); static String getIpv4AddressWithCidrSize(final String ipv4Address, final String netmask); static Boolean validIpRangeList(final String ipRangeList); }
NetUtils { public static String long2Ip(final long ip) { final StringBuilder result = new StringBuilder(15); result.append(ip >> 24 & 0xff).append("."); result.append(ip >> 16 & 0xff).append("."); result.append(ip >> 8 & 0xff).append("."); result.append(ip & 0xff); return result.toString(); }  static long createSequenceBasedMacAddress(final long macAddress); static String getHostName(); static String[] getLocalCidrs(); static String getDefaultHostIp(); static String ipAndNetMaskToCidr(final String ip, final String netmask); static String getCidrNetmask(final long cidrSize); static String getDefaultEthDevice(); static String[] getNetworkParams(final NetworkInterface nic); static boolean isValidIp4(final String ip); static boolean isValidIp4Netmask(final String netmask); static long ip2Long(final String ip); static String long2Ip(final long ip); static String byte2Mac(final byte[] m); static String prefix2Netmask(final short prefix); static InetAddress[] getAllLocalInetAddresses(); static InetAddress[] getInterfaceInetAddresses(final String ifName); static String getLocalIPString(); static InetAddress getLocalInetAddress(); static boolean isLocalAddress(final String strAddress); static boolean isLocalAddress(final InetAddress addr); static String getMacAddress(final InetAddress address); static boolean ipRangesOverlap(final String startIp1, final String endIp1, final String startIp2, final String endIp2); static String[] getNicParams(final String nicName); static boolean isSiteLocalAddress(final String ipAddress); static boolean validIpRange(final String startIP, final String endIP); static boolean validIpRange(final String ipRange); static boolean is31PrefixCidr(final String cidr); static boolean isValidIp4Cidr(final String cidr); static SortedSet<Long> getAllIpsFromCidr(final String cidr, final Set<Long> usedIps); static SortedSet<Long> getAllIpsFromCidr(final String cidr_ip, final long size, final Set<Long> usedIps); static SortedSet<Long> listIp2LongList(final List<String> ipStringList); static long getRandomIpFromCidr(final String startIp, final int size, final SortedSet<Long> avoid); static long getRandomIpFromCidr(final long cidr, final int size, final SortedSet<Long> avoid); static boolean sameSubnet(final String ip1, final String ip2, final String netmask); static String getSubNet(final String ip, final String netmask); static boolean sameSubnetCIDR(final String ip1, final String ip2, final long cidrSize); static String getCidrSubNet(final String ip, final long cidrSize); static Pair<String, Integer> getCidr(final String cidr); static SupersetOrSubset isNetworkASubsetOrSupersetOfNetworkB(final String cidrA, final String cidrB); static Long[] cidrToLong(final String cidr); static String getCidrSubNet(final String cidr); static String getCidrNetmask(final String cidr); static String getCidrHostAddress(final String cidr); static String getCidrHostAddress6(final String cidrv6); static String cidr2Netmask(final String cidr); static boolean isValidPort(final int p); static boolean isValidPort(final String p); static boolean isValidAlgorithm(final String p); static String getLinkLocalNetMask(); static String[] getLinkLocalIPRange(final int size); static String[] getIpRangeFromCidr(final String cidr, final long size); static String getLinkLocalGateway(); static String getLinkLocalIpEnd(); static String getLinkLocalCIDR(); static String getIpRangeEndIpFromCidr(final String cidr, final long size); static String portRangeToString(final int portRange[]); static boolean verifyDomainName(final String domainName); static boolean verifyDomainNameLabel(final String hostName, final boolean isHostName); static String getDhcpRange(final String cidr); static String getIpRangeStartIpFromCidr(final String cidr, final long size); static boolean isSameIpRange(final String cidrA, final String cidrB); static boolean verifyInstanceName(final String instanceName); static boolean isNetworksOverlap(final String cidrA, final String cidrB); static boolean isValidS2SVpnPolicy(final String policyType, final String policys); static boolean isValidCidrList(final String cidrList); static boolean validateGuestCidrList(final String guestCidrList); static boolean validateGuestCidr(final String cidr); static boolean isValidMac(final String macAddr); static boolean isUnicastMac(final String macAddr); static boolean isNetworkAWithinNetworkB(final String cidrA, final String cidrB); static boolean validateIcmpType(final long icmpType); static boolean validateIcmpCode(final long icmpCode); static boolean isValidIp6(final String ip); static boolean isValidIp6Cidr(final String ip6Cidr); static int getIp6CidrSize(final String ip6Cidr); static String getIp6FromRange(final String ip6Range); static List<String> getAllIpsFromRangeList(final String excludedIpsExpression); static List<String> getAllIpsFromRange(final String range); static Boolean isIpRangeListInCidr(final String ipRangeListExpression, final String cidr); static BigInteger countIp6InRange(final String ip6Range); static boolean isIp6InRange(final String ip6, final String ip6Range); static boolean isIp6InNetwork(final IPv6Address ip, final IPv6Network network); static boolean isIp6InNetwork(final String ip6, final String ip6Cidr); static boolean isIp6InNetwork(final String ip6, final String ip6Cidr, final Boolean inclusiveHostCount); static boolean isIp6RangeOverlap(final String ipRange1, final String ipRange2); static String getNextIp6InRange(final String currentIp, final String ipRange); static String standardizeIp6Address(final String ip6Addr); static String standardizeIp6Cidr(final String ip6Cidr); static String standardizeMacAddress(final String macAddr); static boolean isValidVlan(String vlan); static boolean isSameIsolationId(String one, String other); static URI generateUriForPvlan(final String primaryVlan, final String isolatedPvlan); static String getPrimaryPvlanFromUri(final URI uri); static String getIsolatedPvlanFromUri(final URI uri); static String generateMacOnIncrease(final String baseMac, final long l); static long mac2Long(final String macAddress); static String long2Mac(final long macAddress); static boolean isIpWithtInCidrRange(final String ipAddress, final String cidr); static boolean isIpInCidrList(final InetAddress address, final String[] cidrlist); static Boolean IsIpEqualToNetworkOrBroadCastIp(final String requestedIp, final String cidr, final long size); static boolean isNetworkorBroadcastIP(final String ip, final String netmask); static String getCidrFromGatewayAndNetmask(final String gatewayStr, final String netmaskStr); static long getCidrSize(final String netmask); static String getIpv4AddressWithCidrSize(final String ipv4Address, final String netmask); static Boolean validIpRangeList(final String ipRangeList); final static int HTTP_PORT; final static int HTTPS_PORT; final static int VPN_PORT; final static int VPN_NATT_PORT; final static int VPN_L2TP_PORT; final static int HAPROXY_STATS_PORT; final static String UDP_PROTO; final static String TCP_PROTO; final static String ANY_PROTO; final static String ICMP_PROTO; final static String ALL_PROTO; final static String HTTP_PROTO; final static String SSL_PROTO; final static String ALL_IP4_CIDRS; final static String ALL_IP6_CIDRS; final static int PORT_RANGE_MIN; final static int PORT_RANGE_MAX; }