Java Convert via ByteBuffer stringToIpAddress(String s)

Here you can find the source of stringToIpAddress(String s)

Description

string To Ip Address

License

Open Source License

Declaration

public static int stringToIpAddress(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;

public class Main {
    public static int stringToIpAddress(String s) {
        try {//from  ww  w  . j av  a2 s  .  com
            return ByteBuffer.wrap(InetAddress.getByName(s).getAddress()).getInt();
        } catch (UnknownHostException e) {
            return -1;
        }
    }
}

Related

  1. stringsFromBinary(final byte[] binary)
  2. stringsToBinary(final String strings[])
  3. stringToBytes(final String inString)
  4. stringToBytes(String str)
  5. StringToData(String conv, boolean isRe, int number)
  6. stringToLong(String offsetString)
  7. stringToLongUnknownLength(String str, int startIndex)
  8. to32BitsLongArray(byte[] data, boolean bigEndian)
  9. toArray(final byte[] byteArray, final int sizeLimit)