Here you can find the source of ip2bytes(String ip)
static byte[] ip2bytes(String ip)
//package com.java2s; //License from project: Apache License public class Main { static byte[] ip2bytes(String ip) { String[] addrs = ip.split("\\."); if (addrs.length != 4) throw new IllegalArgumentException("ip should be a x.x.x.x"); byte[] bytes = new byte[4]; for (int i = 0; i < 4; i++) { int a = Integer.parseInt(addrs[i]); if (a > 255) throw new IllegalArgumentException("not a legal ip address"); bytes[i] = (byte) a; }/* w w w . j av a2 s . co m*/ return bytes; } }