List of usage examples for com.google.common.net InetAddresses toAddrString
public static String toAddrString(InetAddress ip)
From source file:org.anarres.dhcp.common.address.AbstractMaskedAddress.java
public AbstractMaskedAddress(@Nonnull InetAddress address, @Nonnegative int netmask) { if (netmask > address.getAddress().length * Byte.SIZE) throw new IllegalArgumentException( "Netmask too large: " + InetAddresses.toAddrString(address) + "/" + netmask); this.address = address; this.netmask = netmask; }
From source file:org.graylog.plugins.pipelineprocessor.functions.ips.IpAddress.java
@Override public String toString() { return InetAddresses.toAddrString(address); }
From source file:google.registry.model.host.InetAddressAdapter.java
@Override public AddressShim marshal(InetAddress inetAddress) { AddressShim shim = new AddressShim(); shim.ipAddress = InetAddresses.toAddrString(inetAddress); shim.ipVersion = (inetAddress instanceof Inet6Address) ? "v6" : "v4"; return shim;//from w w w.j ava2 s.co m }
From source file:at.alladin.rmbt.controlServer.QoSTestRequestResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/* www .java 2 s .c om*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); String answerString; final String clientIpRaw = getIP(); final InetAddress clientAddress = InetAddresses.forString(clientIpRaw); final String clientIpString = InetAddresses.toAddrString(clientAddress); System.out.println(MessageFormat.format(labels.getString("NEW_QOS_REQUEST"), clientIpRaw)); if (entity != null && !entity.isEmpty()) { // try parse the string to a JSON object try { request = new JSONObject(entity); List<QoSTestObjective> listTestParams = new ArrayList<>(); QoSTestObjectiveDao testObjectiveDao = new QoSTestObjectiveDao(conn); listTestParams = testObjectiveDao.getByTestClass(1); //listTestParams.add(testObjectiveDao.getById(1)); Map<String, List<JSONObject>> tests = new HashMap<>(); for (QoSTestObjective o : listTestParams) { List<JSONObject> testList; if (tests.containsKey(o.getTestType())) { testList = tests.get(o.getTestType()); } else { testList = new ArrayList<>(); tests.put(o.getTestType(), testList); } JSONObject params = new JSONObject(o.getObjective()); Iterator<String> keys = params.keys(); boolean testInvalid = false; //iterate through all keys and interprete their values if necessary; while (keys.hasNext()) { String key = keys.next(); Object scriptResult = TestScriptInterpreter.interprete(params.getString(key), null); if (scriptResult != null) { params.put(key, String.valueOf(scriptResult)); } else { testInvalid = true; break; } } //add test uid to the params object params.put("qos_test_uid", String.valueOf(o.getUid())); params.put("concurrency_group", String.valueOf(o.getConcurrencyGroup())); if (clientAddress instanceof Inet6Address) { params.put("server_addr", String.valueOf(o.getTestServerIpv6())); } else { params.put("server_addr", String.valueOf(o.getTestServerIpv4())); } params.put("server_port", String.valueOf(o.getPort())); if (!testInvalid) { testList.add(params); } } answer.put("objectives", tests); //System.out.println(answer); answer.put("test_duration", settings.getString("RMBT_DURATION")); answer.put("test_numthreads", settings.getString("RMBT_NUM_THREADS")); answer.put("test_numpings", settings.getString("RMBT_NUM_PINGS")); answer.put("client_remote_ip", clientIpString); } catch (JSONException | SQLException e) { e.printStackTrace(); errorList.addError("ERROR_DB_QOS_GET_OBJECTIVE_NOT_FOUND"); } } try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } answerString = answer.toString(); return answerString; }
From source file:google.registry.rde.HostResourceToXjcConverter.java
/** Converts {@link InetAddress} to {@link XjcHostAddrType}. */ private static XjcHostAddrType convertInetAddress(InetAddress model) { XjcHostAddrType bean = new XjcHostAddrType(); bean.setIp(model instanceof Inet6Address ? XjcHostIpType.V_6 : XjcHostIpType.V_4); bean.setValue(InetAddresses.toAddrString(model)); return bean;/* w w w. ja v a 2 s . com*/ }
From source file:com.gemini.discover.nmap.DiscoveryProviderNmapImpl.java
@Override public List<Host> discoverNetworks(List<GeminiNetwork> networks) { //build the network for nmap String nmapCmd = ""; // networks.stream() // .filter(dn -> dn.isDiscoveryComplete()) // .forEach((dn) -> { // String start = InetAddresses.toAddrString(dn.getStart()); // String end = InetAddresses.toAddrString(dn.getEnd()); ///*w w w . j a v a 2s . c om*/ // //get the last three letters of the end string // Iterable<String> splits = Splitter.on(".").split(end); // for (String s : splits) { // end = s; // } // nmapCmd = start + "-" + end + ","; // }); for (GeminiNetwork dn : networks) { if (!dn.isDiscovered()) { //parse the discovery network from the network object... it can be one or all of the //start/end, network/mask and host String start = InetAddresses.toAddrString(dn.getStart()); String end = InetAddresses.toAddrString(dn.getEnd()); if (!start.isEmpty() && !end.isEmpty()) { //get the last three letters of the end string List<String> splits = Splitter.on(".").splitToList(end); nmapCmd += start + "-" + splits.get(splits.size() - 1); } String net = InetAddresses.toAddrString(dn.getNetwork()); String mask = String.valueOf(dn.getMask()); if (!net.isEmpty() && dn.getMask() > MIN_NETWORK_MASK) { if (!nmapCmd.isEmpty()) { nmapCmd += ","; } nmapCmd += net + "/" + mask; } String host = dn.getHost(); if (!host.isEmpty()) { if (!nmapCmd.isEmpty()) { nmapCmd += ","; } nmapCmd += host; } } } if (nmapCmd.isEmpty()) { //no hosts to discover Logger.error("NMAP Discovery: No hosts to discover"); return null; } NMap nmap = new NMap(); try { //run the nmap.run command, returns a list of hosts List<Host> l = nmap.runCommand(nmapCmd); //store the servers in the database //the other service needs a REST API to add the servers //for now just print to the console //System.out.println(Joiner.on(",").join(l)); return l; } catch (IOException | InterruptedException | ParserConfigurationException | SAXException ex) { Logger.error("NMAP Discovery failed: {}", ex.toString()); return null; } }
From source file:nl.sidn.dnslib.message.records.AAAAResourceRecord.java
@Override public void decode(NetworkData buffer) { super.decode(buffer); //get the 16 raw bytes for the ipv6 address ipv6Bytes = new byte[16]; buffer.readBytes(ipv6Bytes);// w ww. j av a2s .c om //create a textual representation of the address InetAddress ipv6Addres; try { ipv6Addres = InetAddress.getByAddress(ipv6Bytes); } catch (UnknownHostException e) { throw new RuntimeException("Illegal ipv6 address", e); } setAddress(InetAddresses.toAddrString(ipv6Addres)); }
From source file:io.prestosql.type.IpAddressType.java
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; }/*from w w w .jav a 2 s . c o m*/ try { return InetAddresses .toAddrString(InetAddress.getByAddress(block.getSlice(position, 0, getFixedSize()).getBytes())); } catch (UnknownHostException e) { throw new IllegalArgumentException(); } }
From source file:org.asterion.CoreModule.java
@SuppressWarnings("unchecked") @Override// w w w.ja va 2s. co m protected void configure() { bind(DataStore.class).to(CassandraStore.class).in(Singleton.class); Names.bindProperties(binder(), m_props); bind(Properties.class).toInstance(m_props); String hostname = m_props.getProperty("kairosdb.hostname"); bindConstant().annotatedWith(Names.named("HOSTNAME")).to(hostname != null ? hostname : Util.getHostName()); String hostIp = m_props.getProperty("kairosdb.host_ip"); bindConstant().annotatedWith(Names.named("HOST_IP")) .to(hostIp != null ? hostIp : InetAddresses.toAddrString(Util.findPublicIp())); }
From source file:google.registry.whois.NameserverWhoisResponse.java
@Override public String getPlainTextOutput(boolean preferUnicode, String disclaimer) { BasicEmitter emitter = new BasicEmitter(); for (int i = 0; i < hosts.size(); i++) { HostResource host = hosts.get(i); Registrar registrar = getRegistrar(host.getCurrentSponsorClientId()); emitter.emitField("Server Name", maybeFormatHostname(host.getFullyQualifiedHostName(), preferUnicode)) .emitSet("IP Address", host.getInetAddresses(), new Function<InetAddress, String>() { @Override/*from w w w. j a va 2 s.c om*/ public String apply(InetAddress addr) { return InetAddresses.toAddrString(addr); } }).emitField("Registrar", registrar.getRegistrarName()) .emitField("WHOIS Server", registrar.getWhoisServer()) .emitField("Referral URL", registrar.getReferralUrl()); if (i < hosts.size() - 1) { emitter.emitNewline(); } } return emitter.emitLastUpdated(getTimestamp()).emitFooter(disclaimer).toString(); }