Java IP Address to Byte Array ipToBytesByReg(String ipAddr)

Here you can find the source of ipToBytesByReg(String ipAddr)

Description

ip To Bytes By Reg

License

Open Source License

Declaration

public static byte[] ipToBytesByReg(String ipAddr) 

Method Source Code

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

public class Main {

    public static byte[] ipToBytesByReg(String ipAddr) {
        byte[] ret = new byte[4];
        try {// www  . j a v  a 2s.c  o m
            String[] ipArr = ipAddr.split("\\.");
            ret[0] = (byte) (Integer.parseInt(ipArr[0]) & 0xFF);
            ret[1] = (byte) (Integer.parseInt(ipArr[1]) & 0xFF);
            ret[2] = (byte) (Integer.parseInt(ipArr[2]) & 0xFF);
            ret[3] = (byte) (Integer.parseInt(ipArr[3]) & 0xFF);
            return ret;
        } catch (Exception e) {
            throw new IllegalArgumentException(ipAddr + " is invalid IP");
        }

    }
}

Related

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