congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
NetUtils.doGetIpv4AddressFromNetworkInterface
Code IndexAdd Tabnine to your IDE (free)

How to use
doGetIpv4AddressFromNetworkInterface
method
in
org.apache.servicecomb.foundation.common.net.NetUtils

Best Java code snippets using org.apache.servicecomb.foundation.common.net.NetUtils.doGetIpv4AddressFromNetworkInterface (Showing top 2 results out of 315)

origin: apache/servicecomb-java-chassis

private static void doGetHostNameAndHostAddress() {
 try {
  doGetIpv4AddressFromNetworkInterface();
  // getLocalHost will throw exception in some docker image and sometimes will do a hostname lookup and time consuming
  InetAddress localHost = InetAddress.getLocalHost();
  hostName = localHost.getHostName();
  if ((localHost.isAnyLocalAddress() || localHost.isLoopbackAddress() || localHost.isMulticastAddress())
    && !allInterfaceAddresses.isEmpty()) {
   InetAddress availabelAddress = allInterfaceAddresses.values().iterator().next();
   hostAddress = availabelAddress.getHostAddress();
   LOGGER.warn("cannot find a proper host address, choose {}, may not be correct.", hostAddress);
  } else {
   LOGGER.info("get localhost address: {}", localHost.getHostAddress());
   hostAddress = localHost.getHostAddress();
  }
  LOGGER.info(
    "add host name from localhost:" + hostName + ",host address:" + hostAddress);
 } catch (Exception e) {
  LOGGER.error("got exception when trying to get addresses:", e);
  if (allInterfaceAddresses.size() >= 1) {
   InetAddress entry = allInterfaceAddresses.entrySet().iterator().next().getValue();
   // get host name will do a reverse name lookup and is time consuming
   hostName = entry.getHostName();
   hostAddress = entry.getHostAddress();
   LOGGER.info(
     "add host name from interfaces:" + hostName + ",host address:" + hostAddress);
  }
 }
}
origin: org.apache.servicecomb/foundation-common

private static void doGetHostNameAndHostAddress() {
 try {
  doGetIpv4AddressFromNetworkInterface();
  // getLocalHost will throw exception in some docker image and sometimes will do a hostname lookup and time consuming
  InetAddress localHost = InetAddress.getLocalHost();
  hostName = localHost.getHostName();
  if ((localHost.isAnyLocalAddress() || localHost.isLoopbackAddress() || localHost.isMulticastAddress())
    && !allInterfaceAddresses.isEmpty()) {
   InetAddress availabelAddress = allInterfaceAddresses.values().iterator().next();
   hostAddress = availabelAddress.getHostAddress();
   LOGGER.warn("cannot find a proper host address, choose {}, may not be correct.", hostAddress);
  } else {
   hostAddress = localHost.getHostAddress();
  }
  LOGGER.info(
    "add host name from localhost:" + hostName + ",host address:" + hostAddress);
 } catch (Exception e) {
  LOGGER.error("got exception when trying to get addresses:", e);
  if (allInterfaceAddresses.size() >= 1) {
   InetAddress entry = allInterfaceAddresses.entrySet().iterator().next().getValue();
   // get host name will do a reverse name lookup and is time consuming
   hostName = entry.getHostName();
   hostAddress = entry.getHostAddress();
   LOGGER.info(
     "add host name from interfaces:" + hostName + ",host address:" + hostAddress);
  }
 }
}
org.apache.servicecomb.foundation.common.netNetUtilsdoGetIpv4AddressFromNetworkInterface

Javadoc

docker环境中,有时无法通过InetAddress.getLocalHost()获取 ,会报unknown host Exception, system error 此时,通过遍历网卡接口的方式规避,出来的数据不一定对

Popular methods of NetUtils

  • parseIpPortFromURI
  • canTcpListen
  • parseIpPort
  • doGetHostNameAndHostAddress
  • ensureGetInterfaceAddress
  • getHostAddress
  • getHostName
  • getRealListenAddress
    对于配置为0.0.0.0的地址,let it go schema, e.g. http adddress, e.g 0.0.0.0:8080 return 实际监听的地址
  • humanReadableBytes

Popular in Java

  • Reading from database using SQL prepared statement
  • compareTo (BigDecimal)
  • runOnUiThread (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now