Similar to {@link #toAddress(inet.ipaddr.IPAddress.IPVersion)}, but returns null rather than throwing an exception with the address is invalid or does not match the supplied version.
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;
	}
745823
@Override
    public boolean isAnyLocalAddress() {
        byte test = 0x00;
        for (int i = 0; i < INADDRSZ; i++) {
            test |= ipaddress[i];
        }
        return (test == 0x00);
    }
1256189
static InetAddress getNIFirstAddress(int niIndex) throws SocketException {
        if (niIndex > 0) {
            NetworkInterface networkInterface = NetworkInterface.getByIndex(niIndex);
            Enumeration<InetAddress> addressesEnum = networkInterface.getInetAddresses();
            if (addressesEnum.hasMoreElements()) {
                return addressesEnum.nextElement();
            }
        }
        return InetAddress.anyLocalAddress();
    }
1068152
def get_public_ip(addresses, version=4):
        
        for addr in addresses:
            if addr['public'] and addr['address_family'] == version:
                return addr.get('address')
        return None
330761
static Inet4Address anyInet4Address(final NetworkInterface interf) {
        return AccessController.doPrivileged(new PrivilegedAction<Inet4Address>() {
            public Inet4Address run() {
                Enumeration<InetAddress> addrs = interf.getInetAddresses();
                while (addrs.hasMoreElements()) {
                    InetAddress addr = addrs.nextElement();
                    if (addr instanceof Inet4Address) {
                        return (Inet4Address)addr;
                    }
                }
                return null;
            }
        });
    }
467262
public static InetAddress resolveLocalAddress() {
        Set<InetAddress> addrs = resolveLocalAddresses();
        if (addrs != null && !addrs.isEmpty()) return addrs.iterator().next();
        return null;
    }
26946
static int inet4AsInt(InetAddress ia) {
        if (ia instanceof Inet4Address) {
            byte[] addr = ia.getAddress();
            int address  = addr[3] & 0xFF;
            address |= ((addr[2] << 8) & 0xFF00);
            address |= ((addr[1] << 16) & 0xFF0000);
            address |= ((addr[0] << 24) & 0xFF000000);
            return address;
        }
        throw new AssertionError("Should not reach here");
    }
474557
@Override
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {

        try {
            InetAddress toMatch = getAddress();
            // One time only warn against use of wildcard addresses
            if (!anyLocalLogged && toMatch.isAnyLocalAddress()) {
                MGMT_OP_LOGGER.invalidWildcardAddress(this.address, INET_ADDRESS, ANY_ADDRESS);
                anyLocalLogged = true;
            }


            if( toMatch.equals(address) ) {
                if (toMatch instanceof Inet6Address) {
                    return matchIPv6((Inet6Address) toMatch, (Inet6Address) address);
                }
                return toMatch;
            }
        } catch (UnknownHostException e) {
            // One time only log a warning
            if (!unknownHostLogged) {
                MGMT_OP_LOGGER.cannotResolveAddress(this.address);
                unknownHostLogged = true;
            }
            return null;
        }
        return null;
    }
765482
public InetAddress getInetAddress(){
      if(localIP == null){
	 try{
	   localIP = InetAddress.getByName(localHost);
	 }catch(UnknownHostException e){
	   return null;
	 }
      }
      return localIP;
   }
1361187
@Override
  public InetAddress addressLocal()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getLocalAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
823020
private static boolean isIPAdressValid(final String ip){

        // InetAddress.getByName() validates 'null' as a valid IP (localhost).
        // we do not want that
        if (hasValue(ip)) {
            return IP_ADDR_PATTERN.matcher(ip).matches();
        }
        return false;
    }
348808
public static function tryParse(string $ipAddress): ?IPAddressInterface
    {
        if (!self::myParse($ipAddress, $octets)) {
            return null;
        }

        return new self($octets);
    }
293532
@Override
  public InetSocketAddress ipRemote()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return (InetSocketAddress) s.getRemoteSocketAddress();
    }
    else {
      return null;
    }
  }
1138147
public static String getLocalIpv4() {
        InetAddress address = getLocalAddress();
        return address == null ? null : address.getHostAddress();
    }
318482
@Override
    public Address getAddress(final String type, final long id) throws IOException {

        final NominatimReverseRequest q = new NominatimReverseRequest();
        q.setQuery(OsmType.from(type), id);
        return this.getAddress(q);
    }
1302696
@Override
  public InetAddress addressLocal()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return s.getLocalAddress();
    }
    else {
      return null;
    }
  }
470647
@Nullable
    public static String determineIpAddress() throws SocketException {
        SocketException caughtException = null;
        for (final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements();) {
            try {
                final NetworkInterface nextInterface = networkInterfaces.nextElement();
                if (! nextInterface.isLoopback() && ! nextInterface.isVirtual() && ! nextInterface.isPointToPoint()) {
                    for (final Enumeration<InetAddress> addresses = nextInterface.getInetAddresses(); addresses.hasMoreElements(); ) {
                        final InetAddress inetAddress = addresses.nextElement();
                        final byte[] address = inetAddress.getAddress();
                        if ((address.length == 4) //  we don't need no steenking IPv6
                                && ((address[0] != 127) || (address[1] != 0))) {    //  don't want localhost IP
                            return inetAddress.getHostAddress();
                        }
                    }
                }
            } catch (SocketException ex) {
                // We're not going to extract an IP address from this interface, so move on to the next one.
                // If we find a qualifying interface, we won't care that some other interface gave us problems.
                // If we don't find one, this exception might be informative.
                caughtException = ex;
            }
        }

        if (caughtException != null) {
            throw caughtException;
        }
        return null;
    }