List of usage examples for com.google.common.net InetAddresses forString
public static InetAddress forString(String ipString)
From source file:org.eel.kitchen.jsonschema.keyword.common.format.IPV4Validator.java
@Override public ValidationReport validate(final ValidationContext context, final JsonNode instance) throws JsonValidationFailureException { final ValidationReport report = context.createReport(); final String ipaddr = instance.getTextValue(); if (!InetAddresses.isInetAddress(ipaddr)) { report.fail("string is not a valid IPv4 address"); return report; }/*w w w . j a v a 2s .c o m*/ if (InetAddresses.forString(ipaddr).getAddress().length != IPV4_LENGTH) report.fail("string is not a valid IPv4 address"); return report; }
From source file:org.opendaylight.groupbasedpolicy.neutron.mapper.util.Utils.java
/** * This implementation does not use nameservice lookups (e.g. no DNS). * * @param ipAddress - format must be valid for regex in {@link Ipv4Address} or * {@link Ipv6Address}//from w ww.j a va 2 s.c om * @return the {@link IpAddress} having the given ipAddress string representation * @throws IllegalArgumentException - if the argument is not a valid IP address string */ public static IpAddress createIpAddress(String ipAddress) { checkArgument(!Strings.isNullOrEmpty(ipAddress), "Cannot be null or empty."); InetAddress ip = InetAddresses.forString(ipAddress); if (ip instanceof Inet4Address) { return new IpAddress(new Ipv4Address(ipAddress)); } return new IpAddress(new Ipv6Address(ipAddress)); }
From source file:com.gemini.domain.repository.impl.GeminiNetworkRepositoryMongoDBImpl.java
public GeminiNetwork getNetByStartAndEnd(String start, String end) { Datastore ds = getDatastore();//from w ww . j a v a2s . c om if (ds == null) { Logger.error("get networks by start and end - no datastore:{} to {}", start, end); return null; } Logger.debug("get networks by start and end - build query", ToStringBuilder .reflectionToString(this.getClass().getSimpleName(), ToStringStyle.MULTI_LINE_STYLE)); List<GeminiNetwork> retList = ds.find(GeminiNetwork.class).filter("start", InetAddresses.forString(start)) .filter("end", InetAddresses.forString(end)).asList(); for (GeminiNetwork n : retList) { //return the first one in the list Logger.debug("get networks by start and end - found networks:{} to {}", start, end); return n; } Logger.debug("get networks by start and end - did not find the networks:{} to {}", start, end); return null; }
From source file:org.eel.kitchen.jsonschema.format.IPV6FormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV6_LENGTH) return;/*from w w w .j a v a 2s . c o m*/ final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv6 address").addInfo("value", value); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.format.IPV6FormatSpecifier.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV6_LENGTH) return;//w w w .java2 s . c o m final ValidationMessage.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv6 address") .addInfo("value", value); report.addMessage(msg.build()); }
From source file:com.github.fge.jsonschema.format.helpers.IPv4FormatAttribute.java
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String ipaddr = data.getInstance().getNode().textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;//from w ww . jav a 2 s. com report.error(newMsg(data, bundle, "err.format.invalidIPv4Address").putArgument("value", ipaddr)); }
From source file:org.eel.kitchen.jsonschema.format.IPV4FormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;/* w w w. j av a 2s. c o m*/ final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv4 address").addInfo("value", value); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.format.IPV4FormatSpecifier.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;/*from ww w.j a va2s . co m*/ final ValidationMessage.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv4 address") .addInfo("value", value); report.addMessage(msg.build()); }
From source file:at.alladin.rmbt.controlServer.IpResource.java
@Post("json") public String request(final String entity) { addAllowOrigin();/* w ww.java 2 s . c o m*/ 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); System.out.println(MessageFormat.format(labels.getString("NEW_IP_REQ"), clientIpRaw)); if (entity != null && !entity.isEmpty()) { // try parse the string to a JSON object try { // debug parameters sent request = new JSONObject(entity); System.out.println(request.toString(4)); /* sample request data { "api_level": "22", "device": "hammerhead", "language": "de", "last_signal_item": { "lte_rsrp": -106, "lte_rsrq": -11, "lte_rssnr": 300, "network_type_id": 13, "time": 1031122064510 }, "location": { "accuracy": 24, "age": 82517, "altitude": 612, "lat": 47.11288465, "long": 15.1345835, "provider": "gps", "speed": 0 }, "model": "Nexus 5", "os_version": "5.0(1570415)", "plattform": "Android", "product": "hammerhead", "softwareRevision": "master_initial-2413-gf89049d", "softwareVersionCode": 20046, "softwareVersionName": "2.0.46", "timezone": "Europe/Vienna", "type": "MOBILE", "uuid": "........(uuid)........" } */ UUID uuid = null; final String uuidString = request.optString("uuid", ""); if (uuidString.length() != 0) uuid = UUID.fromString(uuidString); final String clientPlattform = request.getString("plattform"); final String clientModel = request.getString("model"); final String clientProduct = request.getString("product"); final String clientDevice = request.getString("device"); final String clientSoftwareVersionCode = request.getString("softwareVersionCode"); final String clientApiLevel = request.getString("api_level"); final JSONObject location = request.optJSONObject("location"); long geoage = 0; // age in ms double geolat = 0; double geolong = 0; float geoaccuracy = 0; // in m double geoaltitude = 0; float geospeed = 0; // in m/s String geoprovider = ""; if (!request.isNull("location")) { geoage = location.optLong("age", 0); geolat = location.optDouble("lat", 0); geolong = location.optDouble("long", 0); geoaccuracy = (float) location.optDouble("accuracy", 0); geoaltitude = location.optDouble("altitude", 0); geospeed = (float) location.optDouble("speed", 0); geoprovider = location.optString("provider", ""); } //final JSONObject lastSignalItem = request.optJSONObject("last_signal_item"); //TODO parse & add to status table if (errorList.getLength() == 0) try { PreparedStatement st; st = conn.prepareStatement( "INSERT INTO status(client_uuid,time,plattform,model,product,device,software_version_code,api_level,ip," + "age,lat,long,accuracy,altitude,speed,provider)" + "VALUES(?, NOW(),?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS); int i = 1; st.setObject(i++, uuid); st.setObject(i++, clientPlattform); st.setObject(i++, clientModel); st.setObject(i++, clientProduct); st.setObject(i++, clientDevice); st.setObject(i++, clientSoftwareVersionCode); st.setObject(i++, clientApiLevel); st.setObject(i++, clientIpRaw); // location information st.setObject(i++, geoage); st.setObject(i++, geolat); st.setObject(i++, geolong); st.setObject(i++, geoaccuracy); st.setObject(i++, geoaltitude); st.setObject(i++, geospeed); st.setObject(i++, geoprovider); final int affectedRows = st.executeUpdate(); if (affectedRows == 0) errorList.addError("ERROR_DB_STORE_STATUS"); } catch (final SQLException e) { errorList.addError("ERROR_DB_STORE_GENERAL"); e.printStackTrace(); } answer.put("ip", clientIpRaw); if (clientAddress instanceof Inet4Address) { answer.put("v", "4"); } else if (clientAddress instanceof Inet6Address) { answer.put("v", "6"); } else { answer.put("v", "0"); } } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSON Data " + e.toString()); } } else { errorList.addErrorString("Expected request is missing."); } 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:org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils.SfcNshHeader.java
public static Long convertIpAddressToLong(Ipv4Address ipv4Address) { return (InetAddresses.coerceToInteger(InetAddresses.forString(ipv4Address.getValue()))) & 0xFFFFFFFFL; }