Here you can find the source of ipToBytesByReg(String ipAddr)
public static byte[] ipToBytesByReg(String ipAddr)
//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"); } } }