import java.io.*;
import java.net.*;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main() {
public static void main(String args[]) throws IOException {
Matcher match;
while (true) {
Process traceRt;
if (System.getProperty("os.name").toLowerCase().contains("win"))
traceRt = Runtime.getRuntime().exec("tracert 8.8.8.8");
else traceRt = Runtime.getRuntime().exec("traceroute 8.8.8.8");
BufferedReader br = new BufferedReader(new InputStreamReader(traceRt.getInputStream()));
String ips = br.readLine();
match = Pattern.compile("(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", Pattern.MULTILINE).matcher(ips);
if (match.find()) break;
}
String myip = match.group();
NetworkInterface networkInterface = null;
Enumeration Interfaces = NetworkInterface.getNetworkInterfaces();
while (Interfaces.hasMoreElements() && networkInterface == null) {
NetworkInterface Interface = (NetworkInterface) Interfaces.nextElement();
Enumeration Addresses = Interface.getInetAddresses();
while (Addresses.hasMoreElements()) {
InetAddress Address = (InetAddress) Addresses.nextElement();
if (Address.getHostAddress().startsWith(myip.split("\\.")[0])) {
networkInterface = Interface;
break;
}
}
}
assert networkInterface != null;
short subnetMask = networkInterface.getInterfaceAddresses().get(1).getNetworkPrefixLength();
byte[] addr = networkInterface.getInterfaceAddresses().get(1).getAddress().getAddress();
}
}