當前位置: 首頁>>代碼示例>>Java>>正文


Java InetAddresses.forString方法代碼示例

本文整理匯總了Java中com.google.common.net.InetAddresses.forString方法的典型用法代碼示例。如果您正苦於以下問題:Java InetAddresses.forString方法的具體用法?Java InetAddresses.forString怎麽用?Java InetAddresses.forString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.net.InetAddresses的用法示例。


在下文中一共展示了InetAddresses.forString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: VersionMessage

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
public VersionMessage(NetworkParameters params, int newBestHeight) {
    super(params);
    clientVersion = params.getProtocolVersionNum(NetworkParameters.ProtocolVersion.CURRENT);
    localServices = 0;
    time = System.currentTimeMillis() / 1000;
    // Note that the Bitcoin Core doesn't do anything with these, and finding out your own external IP address
    // is kind of tricky anyway, so we just put nonsense here for now.
    InetAddress localhost = InetAddresses.forString("127.0.0.1");
    myAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO);
    theirAddr = new PeerAddress(params, localhost, params.getPort(), 0, BigInteger.ZERO);
    subVer = LIBRARY_SUBVER;
    bestHeight = newBestHeight;
    relayTxesBeforeFilter = true;

    length = 85;
    if (protocolVersion > 31402)
        length += 8;
    length += VarInt.sizeOf(subVer.length()) + subVer.length();
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:20,代碼來源:VersionMessage.java

示例2: testValueOfInetAddressIPv4

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Tests valueOf() converter for IPv4 InetAddress.
 */
@Test
public void testValueOfInetAddressIPv4() {
    Ip4Address ipAddress;
    InetAddress inetAddress;

    inetAddress = InetAddresses.forString("1.2.3.4");
    ipAddress = Ip4Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("1.2.3.4"));

    inetAddress = InetAddresses.forString("0.0.0.0");
    ipAddress = Ip4Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("0.0.0.0"));

    inetAddress = InetAddresses.forString("255.255.255.255");
    ipAddress = Ip4Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("255.255.255.255"));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:Ip4AddressTest.java

示例3: checkWifi

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public CheckWifiResult checkWifi(IosDevice device) throws IosDeviceException {
  String output = runAppRobust(device, Duration.ofSeconds(15), "--check_wifi");
  Matcher ipMatcher = CHECK_WIFI_IP_ADDRESS_PATTERN.matcher(output);
  Matcher ssidMatcher = CHECK_WIFI_SSID_PATTERN.matcher(output);

  Optional<WifiConnection> connection;
  if (ipMatcher.find() && ssidMatcher.find()) {
    InetAddress ip = InetAddresses.forString(ipMatcher.group(1));
    String ssid = ssidMatcher.group(1);
    connection = Optional.of(new AutoValue_AppResult_WifiConnection(ip, ssid));
  } else {
    connection = Optional.empty();
  }

  return new CheckWifiResult(output, connection);
}
 
開發者ID:google,項目名稱:ios-device-control,代碼行數:18,代碼來源:OpenUrlApp.java

示例4: testValueOfInetAddressIPv6

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Tests valueOf() converter for IPv6 InetAddress.
 */
@Test
public void testValueOfInetAddressIPv6() {
    Ip6Address ipAddress;
    InetAddress inetAddress;

    inetAddress =
        InetAddresses.forString("1111:2222:3333:4444:5555:6666:7777:8888");
    ipAddress = Ip6Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(),
               is("1111:2222:3333:4444:5555:6666:7777:8888"));

    inetAddress = InetAddresses.forString("::");
    ipAddress = Ip6Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("::"));

    inetAddress =
        InetAddresses.forString("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
    ipAddress = Ip6Address.valueOf(inetAddress);
    assertThat(ipAddress.toString(),
               is("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:Ip6AddressTest.java

示例5: testValueOfInetAddressIPv4

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Tests valueOf() converter for IPv4 InetAddress.
 */
@Test
public void testValueOfInetAddressIPv4() {
    IpAddress ipAddress;
    InetAddress inetAddress;

    inetAddress = InetAddresses.forString("1.2.3.4");
    ipAddress = IpAddress.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("1.2.3.4"));

    inetAddress = InetAddresses.forString("0.0.0.0");
    ipAddress = IpAddress.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("0.0.0.0"));

    inetAddress = InetAddresses.forString("255.255.255.255");
    ipAddress = IpAddress.valueOf(inetAddress);
    assertThat(ipAddress.toString(), is("255.255.255.255"));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:21,代碼來源:IpAddressTest.java

示例6: evaluate

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public IpAddress evaluate(FunctionArgs args, EvaluationContext context) {
    final String ipString = String.valueOf(ipParam.required(args, context));

    try {
        final InetAddress inetAddress = InetAddresses.forString(ipString);
        return new IpAddress(inetAddress);
    } catch (IllegalArgumentException e) {
        final Optional<String> defaultValue = defaultParam.optional(args, context);
        if (!defaultValue.isPresent()) {
            return new IpAddress(ANYV4);
        }
        try {
            return new IpAddress(InetAddresses.forString(defaultValue.get()));
        } catch (IllegalFormatException e1) {
            log.warn("Parameter `default` for to_ip() is not a valid IP address: {}", defaultValue.get());
            throw e1;
        }
    }
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:21,代碼來源:IpAddressConversion.java

示例7: initMutatingEppToolCommand

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
protected void initMutatingEppToolCommand() {
  setSoyTemplate(HostCreateSoyInfo.getInstance(), HostCreateSoyInfo.HOSTCREATE);
  ImmutableList.Builder<String> ipv4Addresses = new ImmutableList.Builder<>();
  ImmutableList.Builder<String> ipv6Addresses = new ImmutableList.Builder<>();
  for (String address : nullToEmpty(addresses)) {
    InetAddress inetAddress = InetAddresses.forString(address);
    if (inetAddress instanceof Inet4Address) {
      ipv4Addresses.add(inetAddress.getHostAddress());
    } else if (inetAddress instanceof Inet6Address) {
      ipv6Addresses.add(inetAddress.getHostAddress());
    } else {
      throw new IllegalArgumentException(
          String.format("IP address in unknown format: %s", address));
    }
  }
  addSoyRecord(
      clientId,
      new SoyMapData(
          "hostname", hostName,
          "ipv4addresses", ipv4Addresses.build(),
          "ipv6addresses", ipv6Addresses.build()));
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:24,代碼來源:CreateHostCommand.java

示例8: test03

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Test
public void test03() throws Exception {
    InetAddress inetAddress = InetAddresses.forString("42.178.17.57");
    InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 8998);
    Proxy proxy = new Proxy(Proxy.Type.HTTP, inetSocketAddress);
    OkHttpClient client = new OkHttpClient.Builder().proxy(proxy).build();
    Request request = new Request.Builder().url("http://www.cnblogs.com/xinz/archive/2011/11/27/2265425.html").build();
    Response execute = client.newCall(request).execute();
    System.out.println(execute.body().string());

    client.newBuilder().proxy(null).build();
}
 
開發者ID:jt120,項目名稱:take,代碼行數:13,代碼來源:TakeTest.java

示例9: makeAddress

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
private InetSocketAddress makeAddress ( final String host, final int port )
{
    try
    {
        // try numeric ip address first
        return new InetSocketAddress ( InetAddresses.forString ( host ), port );
    }
    catch ( final IllegalArgumentException e )
    {
        // assume as hostname
        return InetSocketAddress.createUnresolved ( host, port );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:14,代碼來源:AutoConnectClient.java

示例10: readFrom

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    nodeIp = in.readString();
    nodePort = in.readInt();
    this.address = InetAddresses.forString(nodeIp);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:8,代碼來源:DeleteNodeRequest.java

示例11: valueOf

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Converts an IPv6 string literal (e.g., "1111:2222::8888") into an IP
 * address.
 *
 * @param value an IPv6 address value in string form
 * @return an IPv6 address
 * @throws IllegalArgumentException if the argument is invalid
 */
public static Ip6Address valueOf(String value) {
    InetAddress inetAddress = null;
    try {
        inetAddress = InetAddresses.forString(value);
    } catch (IllegalArgumentException e) {
        final String msg = "Invalid IP address string: " + value;
        throw new IllegalArgumentException(msg);
    }
    return valueOf(inetAddress);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:19,代碼來源:Ip6Address.java

示例12: getPeerAddress

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Returns InetAddress from peer.  The getRemoteAddressString has the form
 * [host][/ip-address]:port.  The host may be missing.  The IP address (and
 * preceding '/') may be missing.  The port preceded by ':' is always present.
 *
 * @return InetAddress from peer
 */
public static InetAddress getPeerAddress(Peer peer) {
  String remoteAddr = peer.getRemoteAddressString().split(":")[0];
  int slashIdx = remoteAddr.indexOf('/');
  return InetAddresses.forString(slashIdx != -1 ?
      remoteAddr.substring(slashIdx + 1, remoteAddr.length()) :
      remoteAddr);
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:15,代碼來源:DataTransferSaslUtil.java

示例13: validIPAddress

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
private boolean validIPAddress(String ipAddress) {
    try {
        InetAddresses.forString(ipAddress);
        return true;
    } catch (Exception e) {
        this.errors.add(e.getMessage());
    }

    return false;
}
 
開發者ID:gocd-contrib,項目名稱:docker-elastic-agents,代碼行數:11,代碼來源:Hosts.java

示例14: lookup

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
/**
 * Returns a loaded GeoEntity object for a given {@code ip}
 * If nothing can be resolved for an {@code ip} , then the city,state and country 
 * for the GeoEntity will be set to 'Unknown'
 * Any futher initializations of the DbIpClient  will not load data into memory again.
 * @param ip The ip (as String) to be resolved.
 * @return a GeoEntity object representing city,state and province info
 */
public GeoEntity lookup(final String ip){
	InetAddress inetAddress = null;
	try{
		inetAddress = InetAddresses.forString(ip);
	}
	catch(final IllegalArgumentException ex){
		logger.error("Invalid IP given",ex);
		throw new InvalidIPException("Invalid IP passed");
	}
	return lookup(inetAddress);
}
 
開發者ID:ankushs92,項目名稱:Java-DB-IP,代碼行數:20,代碼來源:DbIpClient.java

示例15: validateIpAddress

import com.google.common.net.InetAddresses; //導入方法依賴的package包/類
private void validateIpAddress(List<String> errors, String part) {
    try {
        InetAddresses.forString(part);
    } catch (Exception e) {
        errors.add(e.getMessage());
    }
}
 
開發者ID:gocd-contrib,項目名稱:docker-swarm-elastic-agents,代碼行數:8,代碼來源:Hosts.java


注:本文中的com.google.common.net.InetAddresses.forString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。