Here you can find the source of newInterfaceAddress(InetAddress inetAddress, short maskLength)
private static InterfaceAddress newInterfaceAddress(InetAddress inetAddress, short maskLength)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.net.InetAddress; import java.net.InterfaceAddress; public class Main { private static InterfaceAddress newInterfaceAddress(InetAddress inetAddress, short maskLength) { try {//w w w.ja v a2 s .c o m final Constructor<InterfaceAddress> ctor = InterfaceAddress.class.getDeclaredConstructor(); ctor.setAccessible(true); final Field addressField = InterfaceAddress.class.getDeclaredField("address"); addressField.setAccessible(true); final Field maskLengthField = InterfaceAddress.class.getDeclaredField("maskLength"); maskLengthField.setAccessible(true); final InterfaceAddress interfaceAddress = ctor.newInstance(); addressField.set(interfaceAddress, inetAddress); maskLengthField.set(interfaceAddress, maskLength); return interfaceAddress; } catch (final Exception e) { throw new RuntimeException(e); } } }