// Path: base/src/main/java/ru/bartwell/ultradebugger/base/utils/IpUtils.java
// public class IpUtils {
//     private static final String IPV4_BASIC_PATTERN_STRING = "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])";
//     private static final Pattern IPV4_PATTERN = Pattern.compile("^" + IPV4_BASIC_PATTERN_STRING + "$");
// 
//     @Nullable
//     public static String getIpV4() {
//         return getIpAddress(true);
//     }
// 
//     @Nullable
//     public static String getIpV6() {
//         return getIpAddress(false);
//     }
// 
//     @Nullable
//     private static String getIpAddress(boolean useIPv4) {
//         try {
//             List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
//             for (NetworkInterface networkInterface : interfaces) {
//                 List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses());
//                 for (InetAddress address : addresses) {
//                     if (!address.isLoopbackAddress()) {
//                         String resultAddress = address.getHostAddress().toUpperCase();
//                         boolean isIPv4 = isIPv4Address(resultAddress);
//                         if (useIPv4) {
//                             if (isIPv4) {
//                                 return resultAddress;
//                             }
//                         } else {
//                             if (!isIPv4) {
//                                 int delimiter = resultAddress.indexOf('%');
//                                 return delimiter < 0 ? resultAddress : resultAddress.substring(0, delimiter);
//                             }
//                         }
//                     }
//                 }
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     private static boolean isIPv4Address(@NonNull String input) {
//         return IPV4_PATTERN.matcher(input).matches();
//     }
// }


import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import ru.bartwell.ultradebugger.base.utils.IpUtils;
package ru.bartwell.ultradebugger;



/**
 * Created by BArtWell on 01.01.2017.
 */

public class UltraDebugger {

    private static final String TAG = "UltraDebugger";

    private static String sIp;
    private static int sPort;

    public static void start(@NonNull Context context) {
        start(context, HttpServer.DEFAULT_PORT);
    }

    public static void start(@NonNull Context context, int port) {
        sIp = IpUtils.getIpV4();
        sPort = port;
        addLogInfo(port);
        ModulesManager.newInstance(context);
        ServerService.start(context, port);
    }

    public static void stop(@NonNull Context context) {
        ServerService.stop(context);
    }

    public static int getPort() {
        return sPort;
    }

    public static String getIp() {
        return sIp;
    }

    private static void addLogInfo(int port) {
        Log.i(TAG, "-----------------------------");
        Log.i(TAG, "Open browser on computer and type address:");
// Path: base/src/main/java/ru/bartwell/ultradebugger/base/utils/IpUtils.java
// public class IpUtils {
//     private static final String IPV4_BASIC_PATTERN_STRING = "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])";
//     private static final Pattern IPV4_PATTERN = Pattern.compile("^" + IPV4_BASIC_PATTERN_STRING + "$");
// 
//     @Nullable
//     public static String getIpV4() {
//         return getIpAddress(true);
//     }
// 
//     @Nullable
//     public static String getIpV6() {
//         return getIpAddress(false);
//     }
// 
//     @Nullable
//     private static String getIpAddress(boolean useIPv4) {
//         try {
//             List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
//             for (NetworkInterface networkInterface : interfaces) {
//                 List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses());
//                 for (InetAddress address : addresses) {
//                     if (!address.isLoopbackAddress()) {
//                         String resultAddress = address.getHostAddress().toUpperCase();
//                         boolean isIPv4 = isIPv4Address(resultAddress);
//                         if (useIPv4) {
//                             if (isIPv4) {
//                                 return resultAddress;
//                             }
//                         } else {
//                             if (!isIPv4) {
//                                 int delimiter = resultAddress.indexOf('%');
//                                 return delimiter < 0 ? resultAddress : resultAddress.substring(0, delimiter);
//                             }
//                         }
//                     }
//                 }
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     private static boolean isIPv4Address(@NonNull String input) {
//         return IPV4_PATTERN.matcher(input).matches();
//     }
// }


// Path: ultradebugger/src/main/java/ru/bartwell/ultradebugger/UltraDebugger.java
import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import ru.bartwell.ultradebugger.base.utils.IpUtils;

package ru.bartwell.ultradebugger;



/**
 * Created by BArtWell on 01.01.2017.
 */

public class UltraDebugger {

    private static final String TAG = "UltraDebugger";

    private static String sIp;
    private static int sPort;

    public static void start(@NonNull Context context) {
        start(context, HttpServer.DEFAULT_PORT);
    }

    public static void start(@NonNull Context context, int port) {
        sIp = IpUtils.getIpV4();
        sPort = port;
        addLogInfo(port);
        ModulesManager.newInstance(context);
        ServerService.start(context, port);
    }

    public static void stop(@NonNull Context context) {
        ServerService.stop(context);
    }

    public static int getPort() {
        return sPort;
    }

    public static String getIp() {
        return sIp;
    }

    private static void addLogInfo(int port) {
        Log.i(TAG, "-----------------------------");
        Log.i(TAG, "Open browser on computer and type address:");
        if (TextUtils.isEmpty(sIp)) {