Groovy IsipAddress本地

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Groovy IsipAddress本地相关的知识,希望对你有一定的参考价值。

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. }

以上是关于Groovy IsipAddress本地的主要内容,如果未能解决你的问题,请参考以下文章