Return a standard String representation of IPAddress.
See IPAddressName(String) for the formats used for IPv4
and IPv6 addresses.

@throws IOException if the IPAddress cannot be converted to a String
504097
public String getName() throws IOException {
        if (name != null)
            return name;

        if (isIPv4) {
            //IPv4 address or subdomain
            byte[] host = new byte[4];
            System.arraycopy(address, 0, host, 0, 4);
            name = InetAddress.getByAddress(host).getHostAddress();
            if (address.length == 8) {
                byte[] mask = new byte[4];
                System.arraycopy(address, 4, mask, 0, 4);
                name = name + "/" +
                       InetAddress.getByAddress(mask).getHostAddress();
            }
        } else {
            //IPv6 address or subdomain
            byte[] host = new byte[16];
            System.arraycopy(address, 0, host, 0, 16);
            name = InetAddress.getByAddress(host).getHostAddress();
            if (address.length == 32) {
                // IPv6 subdomain: display prefix length

                // copy subdomain into new array and convert to BitArray
                byte[] maskBytes = new byte[16];
                for (int i=16; i < 32; i++)
                    maskBytes[i-16] = address[i];
                BitArray ba = new BitArray(16*8, maskBytes);
                // Find first zero bit
                int i=0;
                for (; i < 16*8; i++) {
                    if (!ba.get(i))
                        break;
                }
                name = name + "/" + i;
                // Verify remaining bits 0
                for (; i < 16*8; i++) {
                    if (ba.get(i)) {
                        throw new IOException("Invalid IPv6 subdomain - set " +
                            "bit " + i + " not contiguous");
                    }
                }
            }
        }
        return name;
    }
125372
public static boolean isIPv4orIPv6Address(String _ipAddress) {
        return IPV4_PATTERN.matcher(_ipAddress).matches() || IPV6_PATTERN.matcher(_ipAddress).matches();
    }
190405
private void readObject(ObjectInputStream s)
        throws IOException, ClassNotFoundException {
        scope_ifname = null;
        scope_ifname_set = false;

        if (getClass().getClassLoader() != Class.class.getClassLoader()) {
            throw new SecurityException ("invalid address type");
        }

        s.defaultReadObject();

        if (ifname != null && !"".equals (ifname)) {
            try {
                scope_ifname = NetworkInterface.getByName(ifname);
                if (scope_ifname == null) {
                    /* the interface does not exist on this system, so we clear
                     * the scope information completely */
                    scope_id_set = false;
                    scope_ifname_set = false;
                    scope_id = 0;
                } else {
                    try {
                        scope_id = deriveNumericScope (scope_ifname);
                    } catch (UnknownHostException e) {
                        // typically should not happen, but it may be that
                        // the machine being used for deserialization has
                        // the same interface name but without IPv6 configured.
                    }
                }
            } catch (SocketException e) {}

        }
        /* if ifname was not supplied, then the numeric info is used */

        ipaddress = ipaddress.clone();

        // Check that our invariants are satisfied
        if (ipaddress.length != INADDRSZ) {
            throw new InvalidObjectException("invalid address length: "+
                                             ipaddress.length);
        }

        if (holder().getFamily() != AF_INET6) {
            throw new InvalidObjectException("invalid address family type");
        }
    }
59331
public String receiveString() throws IOException {
    int len = pgInput.scanCStringLength();
    String res = encoding.decode(pgInput.getBuffer(), pgInput.getIndex(), len - 1);
    pgInput.skip(len);
    return res;
  }
1263172
private static String getIPAddress () {
    String rc;

    try {
      rc = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
      // No FFDC code needed
      rc = Long.valueOf(new Random().nextLong()).toString();
    }

    return rc;
  }
594969
@Override
	public String getString() {
		String result = cachedString;
		if(result == null) {
			synchronized(this) {
				result = cachedString;
				if(result == null) {
					if(isSinglePrefixBlock() || !isMultiple()) { //covers the case of !isMultiple, ie single addresses, when there is no prefix or the prefix is the bit count
						result = getDefaultLowerString();
					} else if(isFullRange()) {
						result = IPAddress.SEGMENT_WILDCARD_STR;
					} else {
						long upperValue = getUpperDivisionValue();
						if(isPrefixBlock()) {
							upperValue &= getDivisionNetworkMask(getDivisionPrefixLength());
						}
						result = getDefaultRangeString(getDivisionValue(), upperValue, getDefaultTextualRadix());
					}
					cachedString = result;
				}
			}
		}
		return result;
	}
838393
public static String intToIpv4String(int i) {
		return new StringBuilder(15).append((i >> 24) & 0xff).append('.').append((i >> 16) & 0xff).append('.')
				.append((i >> 8) & 0xff).append('.').append(i & 0xff).toString();
	}
1270811
public static String normalizeHostName(String name) {
		if (Character.digit(name.charAt(0), 16) != -1) { // it is an IP
			return name;
		} else {
			try {
				InetAddress ipAddress = InetAddress.getByName(name);
				return ipAddress.getHostAddress();
			} catch (UnknownHostException e) {
				return name;
			}
		}
	}
336071
public IPAddress getAddress(IPVersion version) throws IncompatibleAddressException {
		if(!addressProvider.isInvalid()) { // Avoid the exception the second time with this check
			try {
				return toAddress(version);
			} catch(AddressStringException e) { /* note that this exception is cached, it is not lost forever */ }
		}
		return null;
	}
365968
public static String toAddressString(InetSocketAddress address) {
        if (address == null) {
            return StringUtils.EMPTY;
        } else {
            return toIpString(address) + ":" + address.getPort();
        }
    }
79727
public Endpoint withIpAddr(@Nullable String ipAddr) {
        ensureSingle();
        if (ipAddr == null) {
            return withoutIpAddr();
        }

        if (NetUtil.isValidIpV4Address(ipAddr)) {
            return withIpAddr(ipAddr, StandardProtocolFamily.INET);
        }

        if (NetUtil.isValidIpV6Address(ipAddr)) {
            if (ipAddr.charAt(0) == '[') {
                ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
            }
            return withIpAddr(ipAddr, StandardProtocolFamily.INET6);
        }

        throw new IllegalArgumentException("ipAddr: " + ipAddr + " (expected: an IP address)");
    }
1200450
public IPAddress asAddress(IPVersion version) {
		if(isAddress(version)) {
			return parsedHost.asAddress(version);
		}
		return null;
	}
1084229
def from_string(address):
		
		address = address.split('.')
		if len(address) != WIPV4Address.octet_count:
			raise ValueError('Invalid ip address: %s' % address)

		result = WIPV4Address()
		for i in range(WIPV4Address.octet_count):
			result.__address[i] = WBinArray(int(address[i]), WFixedSizeByteArray.byte_size)
		return result
259510
static public String getExternalIpAddress(){
		String ip = null;
		URL url = null;
		BufferedReader in = null;
		
		for (int i = 0; !isIPv4Address(ip) && i < CHECK_IP_ENDPOINTS.length; i ++, url = null, in = null){
			try{
				url = new URL(CHECK_IP_ENDPOINTS[i]);
				in = new BufferedReader(new InputStreamReader(url.openStream()));
				ip = in.readLine(); //you get the IP as a String
			}catch(Exception e){
				System.err.println("Unable to find out external IP address through end point '" + CHECK_IP_ENDPOINTS[i] + "': " + e.getMessage());
				if (in != null){
					try{
						in.close();
					}catch(Exception e2){
						// ignore
					}
				}
			}
		}
		return ip;
		
	}
1368495
private static String stripHostname(final String originalHostname) {

		// Check if the hostname domains the domain separator character
		final int index = originalHostname.indexOf(DOMAIN_SEPARATOR);
		if (index == -1) {
			return originalHostname;
		}

		// Make sure we are not stripping an IPv4 address
		final Matcher matcher = IPV4_PATTERN.matcher(originalHostname);
		if (matcher.matches()) {
			return originalHostname;
		}

		if (index == 0) {
			throw new IllegalStateException("Hostname " + originalHostname + " starts with a " + DOMAIN_SEPARATOR);
		}

		return originalHostname.substring(0, index);
	}
1365117
public long convertIPString(String ip) throws NumberFormatException, 
    IllegalArgumentException {

        StringTokenizer st = new StringTokenizer(ip,".");
        if (st.countTokens() == 4) {
            long ipLong = (Long.parseLong(st.nextToken()) << 24);
            ipLong += (Long.parseLong(st.nextToken()) << 16);
            ipLong += (Long.parseLong(st.nextToken()) << 8);
            ipLong += Long.parseLong(st.nextToken());
            return ipLong;
        }
        else {
            throw new IllegalArgumentException("Invalid IP string");
        }
    }
909573
private static CharSequence convertReverseDNSIPv6(String str, int suffixStartIndex) throws AddressStringException {
		StringBuilder builder = new StringBuilder(suffixStartIndex);
		StringBuilder low = new StringBuilder();
		StringBuilder high = new StringBuilder();
		int segCount = 0;
		for(int i = suffixStartIndex - 1; i >= 0; ) {
			boolean isRange = false;
			for(int j = 0; j < 4; j++) {
				char c1 = str.charAt(i--);
				if(i >= 0) {
					char c2 = str.charAt(i--);
					if(c2 == IPv4Address.SEGMENT_SEPARATOR) {
						if(c1 == IPAddress.SEGMENT_WILDCARD) {
							isRange = true;
							low.append('0');
							high.append('f');
						} else {
							if(isRange) {
								throw new AddressStringException(str, i + 1);
							}
							low.append(c1);
							high.append(c1);
						}
					} else if(c2 == IPAddress.RANGE_SEPARATOR) {
						high.append(c1);
						if(i >= 1) {
							c2 = str.charAt(i--);
							low.append(c2);
							boolean isFullRange = (c2 == '0' && c1 == 'f');
							if(isRange && !isFullRange) {
								throw new AddressStringException(str, i + 1);
							}
							c2 = str.charAt(i--);
							if(c2 != IPv4Address.SEGMENT_SEPARATOR) {
								throw new AddressStringException(str, i + 1);
							}
						} else {
							throw new AddressStringException(str, i);
						}
						isRange = true;
					} else {
						throw new AddressStringException(str, i + 1);
					}
				} else if(j < 3) {
					throw new AddressStringException(str, i + 1);
				} else {
					if(c1 == IPAddress.SEGMENT_WILDCARD) {
						isRange = true;
						low.append('0');
						high.append('f');
					} else {
						if(isRange) {
							throw new AddressStringException(str, 0);
						}
						low.append(c1);
						high.append(c1);
					}
				}
			}
			segCount++;
			if(builder.length() > 0) {
				builder.append(IPv6Address.SEGMENT_SEPARATOR);
			}
			builder.append(low);
			if(isRange) {
				builder.append(IPAddress.RANGE_SEPARATOR).append(high);
			}
			low.setLength(0);
			high.setLength(0);
		}
		if(segCount != IPv6Address.SEGMENT_COUNT) {
			throw new AddressStringException(str, 0);
		}
		return builder;
	}