Posted By

laurenceosx on 05/16/13


Tagged

groovy


Versions (?)

Groovy IsIpAddressLocal


 / Published in: Groovy
 

URL: http://stackoverflow.com/questions/2406341/how-to-check-if-an-ip-address-is-the-local-host-on-a-multi-homed-system

See: // http://stackoverflow.com/questions/2406341/how-to-check-if-an-ip-address-is-the-local-host-on-a-multi-homed-system

  1. public static boolean isInetAddressLocal(InetAddress addr) {
  2. // http://stackoverflow.com/questions/2406341/how-to-check-if-an-ip-address-is-the-local-host-on-a-multi-homed-system
  3. if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return true; }
  4. // Check if the address is defined on any interface
  5. try { return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { return false;}
  6. }
  7.  
  8. public static boolean isIpStringAddressLocal(String strIpAddress) {
  9. def addr = InetAddress.getByName( strIpAddress );
  10. // http://stackoverflow.com/questions/2406341/how-to-check-if-an-ip-address-is-the-local-host-on-a-multi-homed-system
  11. if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return true; }
  12. // Check if the address is defined on any interface
  13. try { return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { return false;}
  14. }

Report this snippet  

You need to login to post a comment.