List of usage examples for com.google.common.net InetAddresses forString
public static InetAddress forString(String ipString)
From source file:net.bican.iplib.sample.Sample.java
public static void main(String[] args) { // creating a network range by CIDR address CIDR cidr1 = new CIDR("10.10.10.0/30"); Range<IPAddress> range1 = IPAddresses.fromCIDR(cidr1); // iterating a network range Iterables.all(new AddressIterable(range1), new Predicate<IPAddress>() { @Override// w ww .j a v a 2s . c o m public boolean apply(IPAddress input) { System.out.println(input); return true; } }); // creating a network range by netmask Netmask netmask1 = new Netmask("10.10.20.0/255.255.255.0"); Range<IPAddress> range2 = IPAddresses.fromNetmask(netmask1); System.out.println("range contains ip: " + range2.contains(IPAddress.getInstance(InetAddresses.forString("10.10.20.20")))); System.out.println("range contains ip: " + range2.contains(IPAddress.getInstance(InetAddresses.forString("10.10.21.20")))); // creating a network range from an arbitrary interval Range<IPAddress> interval = Range.closed(IPAddress.getInstance(InetAddresses.forString("1.0.0.1")), IPAddress.getInstance(InetAddresses.forString("1.0.2.22"))); Set<Range<IPAddress>> ips = IPAddresses.fromInterval(interval); for (Range<IPAddress> i : ips) { System.out.println(i); } }
From source file:com.google.caliper.worker.WorkerMain.java
public static void main(String[] args) throws Exception { // TODO(lukes): instead of parsing the spec from the command line pass the port number on the // command line and then receive the spec from the socket. This way we can start JVMs prior // to starting experiments and thus get better experiment latency. WorkerSpec request = CommandLineSerializer.parse(args[0]); // nonblocking connect so we can interleave the system call with injector creation. SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false);//from w w w .j a v a 2 s.c o m channel.connect(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), request.port)); Injector workerInjector = Guice.createInjector(PRODUCTION, new BenchmarkClassModule(Class.forName(request.benchmarkSpec.className())), new BridgeModule(), ExperimentModule.forWorkerSpec(request), new WorkerModule(request)); Worker worker = workerInjector.getInstance(Worker.class); WorkerEventLog log = new WorkerEventLog(OpenedSocket.fromSocket(channel)); log.notifyWorkerStarted(request.trialId); try { worker.setUpBenchmark(); log.notifyBootstrapPhaseStarting(); worker.bootstrap(); log.notifyMeasurementPhaseStarting(); boolean keepMeasuring = true; boolean isInWarmup = true; while (keepMeasuring) { worker.preMeasure(isInWarmup); log.notifyMeasurementStarting(); try { ShouldContinueMessage message = log.notifyMeasurementEnding(worker.measure()); keepMeasuring = message.shouldContinue(); isInWarmup = !message.isWarmupComplete(); } finally { worker.postMeasure(); } } } catch (Exception e) { log.notifyFailure(e); } finally { System.out.flush(); // ? worker.tearDownBenchmark(); log.close(); } }
From source file:com.accumulobook.designs.lexicoder.CustomLexicoderExample.java
public static void main(String[] args) throws Exception { Connector conn = ExampleMiniCluster.getConnector(); List<String> addrs = new ArrayList<>(); addrs.add("192.168.1.1"); addrs.add("192.168.1.2"); addrs.add("192.168.11.1"); addrs.add("192.168.11.11"); addrs.add("192.168.11.100"); addrs.add("192.168.11.101"); addrs.add("192.168.100.1"); addrs.add("192.168.100.2"); addrs.add("192.168.100.12"); conn.tableOperations().create("addresses"); BatchWriter writer = conn.createBatchWriter("addresses", new BatchWriterConfig()); // ingest using just address strings for (String addrString : addrs) { Mutation m = new Mutation(addrString); m.put("", "address string", addrString); writer.addMutation(m);//from w w w . ja v a 2s. co m } writer.flush(); System.out.println("sort order using strings"); Scanner scanner = conn.createScanner("addresses", Authorizations.EMPTY); for (Map.Entry<Key, Value> e : scanner) { System.out.println(e.getValue()); } // delete rows conn.tableOperations().deleteRows("addresses", null, null); // ingest using lexicoder Inet4AddressLexicoder lexicoder = new Inet4AddressLexicoder(); for (String addrString : addrs) { InetAddress addr = InetAddresses.forString(addrString); byte[] addrBytes = lexicoder.encode((Inet4Address) addr); Mutation m = new Mutation(addrBytes); m.put("", "address string", addrString); writer.addMutation(m); } writer.close(); // scan again System.out.println("\nsort order using lexicoder"); for (Map.Entry<Key, Value> e : scanner) { System.out.println(e.getValue()); } }
From source file:at.alladin.rmbt.shared.GeoIPHelper.java
public static void main(String[] args) { System.out.println(lookupCountry(InetAddresses.forString("2a01:190:1700:39::75"))); System.out.println(lookupCountry(InetAddresses.forString("78.47.24.204"))); }
From source file:org.opendaylight.sxp.util.ArraysUtil.java
/** * @param ip String representation of ip address * @return BitSet representing ip address *///from w w w .ja va 2 s . co m public static BitSet getBitAddress(String ip) { byte[] address = InetAddresses.forString(ip).getAddress(); for (int i = 0; i < address.length; i++) { address[i] = ArraysUtil.reverseBitsByte(address[i]); } return BitSet.valueOf(address); }
From source file:org.anarres.dhcp.common.address.InterfaceAddress.java
/** * Constructs an InterfaceAddress from a String of the form 1.2.3.4/25. * * @throws IllegalArgumentException if the argument was duff. *//*from w w w .j av a 2s .co m*/ @Nonnull public static InterfaceAddress forString(@Nonnull String addressString) { String netmaskString = null; int idx = addressString.indexOf('/'); if (idx != -1) { netmaskString = addressString.substring(idx + 1); addressString = addressString.substring(0, idx); } InetAddress address = InetAddresses.forString(addressString); int netmask; if (netmaskString != null) { try { netmask = Integer.parseInt(netmaskString); } catch (NumberFormatException e) { throw new IllegalArgumentException("Cannot parse netmask from " + netmaskString, e); } } else { netmask = address.getAddress().length * Byte.SIZE; } return new InterfaceAddress(address, netmask); }
From source file:io.airlift.http.server.Inet4Networks.java
public static boolean isPrivateNetworkAddress(String inetAddress) { Inet4Address address = InetAddresses.getCoercedIPv4Address(InetAddresses.forString(inetAddress)); return isPrivateNetworkAddress(address); }
From source file:com.navercorp.pinpoint.common.server.util.InetAddressUtils.java
public static List<InetAddress> toInetAddressList(List<String> addressList) { if (CollectionUtils.isEmpty(addressList)) { return Collections.emptyList(); }/*from w w w. j av a 2 s. c om*/ final List<InetAddress> inetAddressList = new ArrayList<InetAddress>(addressList.size()); for (String ignoreAddress : addressList) { if (StringUtils.isBlank(ignoreAddress)) { continue; } // not throw UnknownHostException final InetAddress address = InetAddresses.forString(ignoreAddress); if (address != null) { inetAddressList.add(address); } } return inetAddressList; }
From source file:org.opendaylight.protocol.util.Ipv6Util.java
/** * Creates uncompressed IP Address// w ww.ja v a 2 s.c o m * * @param ip to be uncompressed * @return Ipv6Address with same, but uncompressed, value */ public static Ipv6Address getFullForm(final Ipv6Address ip) { return new Ipv6Address(InetAddresses.forString(ip.getValue()).getHostAddress()); }
From source file:zipkin.storage.elasticsearch.http.PseudoAddressRecordSet.java
static Dns create(List<String> urls, Dns actualDns) { Set<String> schemes = Sets.newLinkedHashSet(); Set<String> hosts = Sets.newLinkedHashSet(); Set<InetAddress> ipAddresses = Sets.newLinkedHashSet(); Set<Integer> ports = Sets.newLinkedHashSet(); for (String url : urls) { HttpUrl httpUrl = HttpUrl.parse(url); schemes.add(httpUrl.scheme());/*from w ww .ja v a 2s .co m*/ if (InetAddresses.isInetAddress(httpUrl.host())) { ipAddresses.add(InetAddresses.forString(httpUrl.host())); } else { hosts.add(httpUrl.host()); } ports.add(httpUrl.port()); } checkArgument(ports.size() == 1, "Only one port supported with multiple hosts %s", urls); checkArgument(schemes.size() == 1 && schemes.iterator().next().equals("http"), "Only http supported with multiple hosts %s", urls); if (hosts.isEmpty()) return new StaticDns(ipAddresses); return new ConcatenatingDns(ipAddresses, hosts, actualDns); }