List of usage examples for java.net InetAddress getAddress
public byte[] getAddress()
From source file:Main.java
public static boolean isTeredo(InetAddress addr) { if (!(addr instanceof Inet6Address)) return false; byte[] bytes = addr.getAddress(); // check for the 2001:0000::/32 prefix, i.e. teredo return bytes[0] == 0x20 && bytes[1] == 0x01 && bytes[2] == 0x00 && bytes[3] == 0x00; }
From source file:Main.java
public static boolean is6to4(InetAddress addr) { if (!(addr instanceof Inet6Address)) return false; byte[] bytes = addr.getAddress(); // check for the 2002::/16 prefix, i.e. 6to4 return bytes[0] == 0x20 && bytes[1] == 0x02; }
From source file:NetUtil.java
/** * Resolves hostname and returns ip address as a string. *//* w ww . ja va2 s .com*/ public static String resolveHost(String hostname) { try { InetAddress addr = Inet4Address.getByName(hostname); byte[] ipAddr = addr.getAddress(); StringBuilder ipAddrStr = new StringBuilder(15); for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr.append('.'); } ipAddrStr.append(ipAddr[i] & 0xFF); } return ipAddrStr.toString(); } catch (UnknownHostException uhex) { return null; } }
From source file:io.netlibs.bgp.protocol.BinaryNextHop.java
public static BinaryNextHop fromRDandNextHop(AbstractRouteDistinguisherType nhrd, InetAddress nhaddr) { byte[] overallNH = new byte[8 + nhaddr.getAddress().length]; // Copy the RD type System.arraycopy(nhrd.getType(), 0, overallNH, 0, 2); // followed by the RD System.arraycopy(nhrd.getBytes(), 0, overallNH, 2, 6); // and the RD address System.arraycopy(nhaddr.getAddress(), 0, overallNH, 8, nhaddr.getAddress().length); return new BinaryNextHop(overallNH); }
From source file:UuidGenerator.java
/** * Initializes the factory.//w w w. j av a 2s.co m * * @param obj */ private synchronized static void initialize(final Object obj) { try { InetAddress inet = InetAddress.getLocalHost(); byte[] bytes = inet.getAddress(); String hexInetAddress = hexFormat(getInt(bytes), 8); String thisHashCode = hexFormat(System.identityHashCode(obj), 8); s_midValue = hexInetAddress + thisHashCode; s_seeder = new SecureRandom(); s_seeder.nextInt(); } catch (java.net.UnknownHostException e) { throw new Error("can not initialize the UuidGenerator generator"); } s_initialized = true; }
From source file:netflow.NetworkDefinition.java
public static long addrToLong(InetAddress address) { byte[] rawIP = address.getAddress(); return convertToLong(rawIP); }
From source file:de.upb.wdqa.wdvd.geolocation.GeolocationDatabase.java
public static GeoInformation getGeoInformation(String str) { GeoInformation result = null;/*ww w .j av a 2 s .c o m*/ try { InetAddress adress = InetAddress.getByName(str); byte[] bytes = adress.getAddress(); ArrayUtils.reverse(bytes); BigInteger bigInt = new BigInteger(1, adress.getAddress()); long longAdress = bigInt.longValue(); result = getGeoInformation(longAdress); } catch (UnknownHostException e) { logger.error("IP Adress not known: " + str); } return result; }
From source file:org.thoughtcrime.securesms.mms.MmsCommunication.java
private static void checkRouteToHost(Context context, String host) throws IOException { InetAddress inetAddress = InetAddress.getByName(host); byte[] ipAddressBytes = inetAddress.getAddress(); int ipAddress = Conversions.byteArrayToIntLittleEndian(ipAddressBytes, 0); ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (!manager.requestRouteToHost(MmsDownloader.TYPE_MOBILE_MMS, ipAddress)) throw new IOException("Connection manager could not obtain route to host."); // if (!manager.requestRouteToHost(ConnectivityManager.TYPE_MOBILE, ipAddress)) // throw new IOException("Connection manager could not obtain route to host."); }
From source file:org.bml.util.io.net.NetworkUtils.java
/** * <p>/* w w w.j a va 2 s . c o m*/ * Conversion utility for changing an ip address String into a positive integer. * This is very handy for range searches, bucketing, and storage in data stores that * do not have built in IP address storage and query models. * </p> * * @param ipString A string representing an IPV4 IP address or a network host name. * @return a positive integer representation of an IP address * @throws UnknownHostException per InetAddress.getByName(ipString) * @throws NullPointerException if the passed ipString is null * @throws IllegalArgumentException if the passed ipString.isEmpty() * * @pre ipString!=null * @pre !ipString.isEmpty() * */ public static Integer toNumericIp(final String ipString) throws UnknownHostException, NullPointerException, IllegalArgumentException { if (CHECKED) { Preconditions.checkNotNull(ipString, "Can not convert a null ipString to a numeric IP"); Preconditions.checkArgument(ipString.isEmpty(), "Can not convert an empty ipString to a numeric IP"); } try { InetAddress ip = InetAddress.getByName(ipString); return ConversionUtils.byteArrayToUnsignedInt(ip.getAddress()); } catch (UnknownHostException ex) { if (LOG.isDebugEnabled()) { LOG.debug("UnknownHostException Found while converting String " + ipString + " IPV4 adress to unsigned int.", ex); } throw ex; } }
From source file:Main.java
/** * hostname from string to int//from w ww . j a va2 s .c o m * @param hostname * @return */ public static int lookupHost(String hostname) { InetAddress inetAddress; try { inetAddress = InetAddress.getByName(hostname); } catch (UnknownHostException e) { return -1; } byte[] addrBytes; int addr; addrBytes = inetAddress.getAddress(); addr = ((addrBytes[3] & 0xff) << 24) | ((addrBytes[2] & 0xff) << 16) | ((addrBytes[1] & 0xff) << 8) | (addrBytes[0] & 0xff); return addr; }