本文整理汇总了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();
}
示例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"));
}
示例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);
}
示例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"));
}
示例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"));
}
示例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;
}
}
}
示例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()));
}
示例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();
}
示例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 );
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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());
}
}