brooklyn.util.net.Networking.getInetAddressWithFixedName()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中brooklyn.util.net.Networking.getInetAddressWithFixedName()方法的一些代码示例,展示了Networking.getInetAddressWithFixedName()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Networking.getInetAddressWithFixedName()方法的具体详情如下:
包路径:brooklyn.util.net.Networking
类名称:Networking
方法名:getInetAddressWithFixedName

Networking.getInetAddressWithFixedName介绍

[英]Gets an InetAddress using the given hostname or IP. If it is an IPv4 address, then this is equivalent to getInetAddressWithFixedName(byte[]). If it is a hostname, then this hostname will be used in the returned InetAddress.
[中]使用给定的主机名或IP获取InetAddress。如果是IPv4地址,那么这相当于getInetAddressWithFixedName(字节[])。如果它是一个主机名,那么这个主机名将用于返回的地址。

代码示例

代码示例来源:origin: io.brooklyn/brooklyn-core

@Override
  public InetAddress apply(String input) {
    return Networking.getInetAddressWithFixedName(input);
  }
});

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** returns the netmask for this cidr; e.g. for a /24 cidr returns 255.255.255.0 */
public InetAddress netmask() {
  final byte[] netmaskBytes = new byte[] { 0, 0, 0, 0 };
  int lengthLeft = length;
  int i=0;
  while (lengthLeft>0) {
    if (lengthLeft>=8) {
      netmaskBytes[i] = (byte)255;
    } else {
      netmaskBytes[i] = (byte) ( (1 << lengthLeft) - 1 );
    }
    lengthLeft -= 8;
    i++;
  }
  return Networking.getInetAddressWithFixedName(netmaskBytes);
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** @deprecated use {@link Networking#getInetAddressWithFixedName(byte[])} */
@Deprecated
public static InetAddress getInetAddressWithFixedName(byte[] ip) {
  return Networking.getInetAddressWithFixedName(ip);
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** returns local IP address, or 127.0.0.1 if it cannot be parsed */
public static InetAddress getLocalHost() {
  try {
    return InetAddress.getLocalHost();
  } catch (UnknownHostException e) {
    InetAddress result = null;
    result = getInetAddressWithFixedName("127.0.0.1");
    log.warn("Localhost is not resolvable; using "+result);
    return result;
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

public static InetAddress getInetAddressWithFixedName(int ip1, int ip2, int ip3, int ip4, int ip5, int ip6) {
  return getInetAddressWithFixedName(asByteArray(ip1, ip2, ip3, ip4, ip5, ip6));
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** As {@link #isPrivateSubnet(InetAddress)} but taking a string; sepcifically local-only address ARE treated as private. 
 * does not require the string to be resolvable, and things which aren't resolvable are treated as private 
 * unless they are known to be local-only */
public static boolean isPrivateSubnet(String hostnameOrIp) {
  Preconditions.checkNotNull(hostnameOrIp, "hostnameOrIp");
  try {
    InetAddress ia = getInetAddressWithFixedName(hostnameOrIp);
    return isPrivateSubnet(ia);
  } catch (Exception e) {
    log.debug("Networking cannot resolve "+hostnameOrIp+": assuming it IS a private address");
    return true;
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

public static InetAddress getInetAddressWithFixedName(int ip1, int ip2, int ip3, int ip4) {
  return getInetAddressWithFixedName(asByteArray(ip1, ip2, ip3, ip4));
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** taking the addresses in the CIDR in order, returns the one in the offset^th position 
 * (starting with the CIDR itself, even if final bits are 0) */
public InetAddress addressAtOffset(int offset) {
  int[] ints = getBytes();
  ints[3] += offset;
  {
    int i=3;
    while (ints[i]>=256) {
      ints[i-1] += (ints[i] / 256);
      ints[i] %= 256;
      i--;
    }
  }
  byte[] bytes = new byte[] { 0, 0, 0, 0 };
  for (int i=0; i<4; i++)
    bytes[i] = (byte) ints[i];
  return Networking.getInetAddressWithFixedName(bytes);
}

代码示例来源:origin: io.brooklyn/brooklyn-utils-common

/** As {@link #isLocalOnly(InetAddress)} but taking a string; 
 * does not require the string to be resolvable, and generally treats non-resolvable hostnames as NOT local-only
 * (although they are treated as private by {@link #isPrivateSubnet(String)}),
 * although certain well-known hostnames are recognised as local-only */
public static boolean isLocalOnly(String hostnameOrIp) {
  Preconditions.checkNotNull(hostnameOrIp, "hostnameOrIp");
  if ("127.0.0.1".equals(hostnameOrIp)) return true;
  if ("localhost".equals(hostnameOrIp)) return true;
  if ("localhost.localdomain".equals(hostnameOrIp)) return true;
  try {
    InetAddress ia = getInetAddressWithFixedName(hostnameOrIp);
    return isLocalOnly(ia);
  } catch (Exception e) {
    log.debug("Networking cannot resolve "+hostnameOrIp+": assuming it is not a local-only address, but it is a private address");
    return false;
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-software-webapp

InetAddress addr = Networking.getInetAddressWithFixedName(ip);
geoH = HostGeoInfo.fromIpAddress(addr);
if (log.isTraceEnabled()) log.trace("GeoDns inferred GeoInfo {} from ip {} (could not infer from hostname {})", new Object[] {geoH, ip, hostname});

代码示例来源:origin: io.brooklyn/brooklyn-cli

InetAddress ip = Networking.getInetAddressWithFixedName(bindAddress);
launcher.bindAddress(ip);

相关文章