Here you can find the source of getLocalAddress()
public static byte[] getLocalAddress()
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.util.regex.Pattern; public class Main { private static final Pattern pattern = Pattern.compile("\\.", Pattern.CASE_INSENSITIVE); private static byte[] localAddress; public static byte[] getLocalAddress() { if (localAddress == null) { try { InetAddress inetAddress = InetAddress.getLocalHost(); localAddress = inetAddress.getAddress(); } catch (Exception e) { }//from ww w . j ava2 s .c o m } return localAddress; } public static byte[] getAddress(String addr) { String[] array = pattern.split(addr); if (array.length != 4) { return new byte[] { 0x00, 0x00, 0x00, 0x00 }; } byte[] bytes = new byte[4]; for (int i = 0; i < array.length; i++) { try { bytes[i] = (byte) Integer.parseInt(array[i]); } catch (Exception e) { return new byte[] { 0x00, 0x00, 0x00, 0x00 }; } } return bytes; } }