Java IP Address to Byte Array ipv4StringToByteArrayUnchecked(String str)

Here you can find the source of ipv4StringToByteArrayUnchecked(String str)

Description

ipv String To Byte Array Unchecked

License

Open Source License

Declaration

public static byte[] ipv4StringToByteArrayUnchecked(String str) 

Method Source Code

//package com.java2s;
/*// w  w  w. j a  v a2s.  c o  m
 *
 * Copyright (C) 2014 Ruediger Gad
 *
 * This file is part of clj-net-pcap.
 *
 * clj-net-pcap is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL) as
 * published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * clj-net-pcap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License (LGPL) for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License (LGPL)
 * along with clj-net-pcap.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static byte[] ipv4StringToByteArrayUnchecked(String str) {
        byte[] ret = new byte[4];

        String[] s = str.split("\\.");

        for (int i = 0; i < ret.length; i++) {
            ret[i] = (byte) Integer.parseInt(s[i], 10);
        }

        return ret;
    }
}

Related

  1. ip2bytes(String ipAddr)
  2. ipToByte(String ip)
  3. ipToByte(String ip)
  4. IpToBytes(String ip)
  5. ipToBytesByReg(String ipAddr)
  6. ipv4ToBytes(String ipv4)
  7. ipv4ToBytes(String ipv4)
  8. ipv4ToBinary(String ip)