// Path: app/src/main/java/com/aaronjwood/portauthority/async/WanIpAsyncTask.java
// public class WanIpAsyncTask extends AsyncTask<Void, Void, String> {
// 
//     // IP service is 100% open source https://github.com/aaronjwood/public-ip-api
//     private static final String EXTERNAL_IP_SERVICE = "https://yourip.aaronjwood.com/";
//     private final WeakReference<MainAsyncResponse> delegate;
// 
//     /**
//      * Constructor to set the delegate
//      *
//      * @param delegate Called when the external IP has been fetched
//      */
//     public WanIpAsyncTask(MainAsyncResponse delegate) {
//         this.delegate = new WeakReference<>(delegate);
//     }
// 
//     /**
//      * Fetch the external IP address
//      *
//      * @param params
//      * @return External IP address
//      */
//     @Override
//     @SuppressLint("NewApi")
//     protected String doInBackground(Void... params) {
//         MainAsyncResponse activity = delegate.get();
//         Context ctx = (Context) activity;
//         OkHttpClient httpClient = new OkHttpClient();
//         Request request = new Request.Builder().url(EXTERNAL_IP_SERVICE).build();
// 
//         try (Response response = httpClient.newCall(request).execute()) {
//             ResponseBody body = response.body();
//             if (!response.isSuccessful() || body == null) {
//                 return ctx.getResources().getString(R.string.errExternIp);
//             }
// 
//             return body.string().trim();
//         } catch (IOException e) {
//             return ctx.getResources().getString(R.string.errExternIp);
//         }
//     }
// 
//     /**
//      * Calls the delegate when the external IP has been fetched
//      *
//      * @param result External IP address
//      */
//     @Override
//     protected void onPostExecute(String result) {
//         MainAsyncResponse activity = delegate.get();
//         if (activity != null) {
//             activity.processFinish(result);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/aaronjwood/portauthority/response/MainAsyncResponse.java
// public interface MainAsyncResponse extends ErrorAsyncResponse {
// 
//     /**
//      * Delegate to handle Host + AtomicInteger outputs
//      *
//      * @param h
//      * @param i
//      */
//     void processFinish(Host h, AtomicInteger i);
// 
//     /**
//      * Delegate to handle integer outputs
//      *
//      * @param output
//      */
//     void processFinish(int output);
// 
//     /**
//      * Delegate to handle string outputs
//      *
//      * @param output
//      */
//     void processFinish(String output);
// 
//     /**
//      * Delegate to handle boolean outputs
//      *
//      * @param output
//      */
//     void processFinish(boolean output);
// 
// }


import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import com.aaronjwood.portauthority.async.WanIpAsyncTask;
import com.aaronjwood.portauthority.response.MainAsyncResponse;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteOrder;
import java.util.Enumeration;


    /**
     * Gets the device's internal LAN IP address associated with the cellular network
     *
     * @return Local cellular network LAN IP address
     */
    public static String getInternalMobileIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en != null && en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                        return inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException ex) {
            return "Unknown";
        }

        return "Unknown";
    }

    /**
     * Gets the device's external (WAN) IP address
     *
     * @param delegate Called when the external IP address has been fetched
     */
// Path: app/src/main/java/com/aaronjwood/portauthority/async/WanIpAsyncTask.java
// public class WanIpAsyncTask extends AsyncTask<Void, Void, String> {
// 
//     // IP service is 100% open source https://github.com/aaronjwood/public-ip-api
//     private static final String EXTERNAL_IP_SERVICE = "https://yourip.aaronjwood.com/";
//     private final WeakReference<MainAsyncResponse> delegate;
// 
//     /**
//      * Constructor to set the delegate
//      *
//      * @param delegate Called when the external IP has been fetched
//      */
//     public WanIpAsyncTask(MainAsyncResponse delegate) {
//         this.delegate = new WeakReference<>(delegate);
//     }
// 
//     /**
//      * Fetch the external IP address
//      *
//      * @param params
//      * @return External IP address
//      */
//     @Override
//     @SuppressLint("NewApi")
//     protected String doInBackground(Void... params) {
//         MainAsyncResponse activity = delegate.get();
//         Context ctx = (Context) activity;
//         OkHttpClient httpClient = new OkHttpClient();
//         Request request = new Request.Builder().url(EXTERNAL_IP_SERVICE).build();
// 
//         try (Response response = httpClient.newCall(request).execute()) {
//             ResponseBody body = response.body();
//             if (!response.isSuccessful() || body == null) {
//                 return ctx.getResources().getString(R.string.errExternIp);
//             }
// 
//             return body.string().trim();
//         } catch (IOException e) {
//             return ctx.getResources().getString(R.string.errExternIp);
//         }
//     }
// 
//     /**
//      * Calls the delegate when the external IP has been fetched
//      *
//      * @param result External IP address
//      */
//     @Override
//     protected void onPostExecute(String result) {
//         MainAsyncResponse activity = delegate.get();
//         if (activity != null) {
//             activity.processFinish(result);
//         }
//     }
// }
// 
// Path: app/src/main/java/com/aaronjwood/portauthority/response/MainAsyncResponse.java
// public interface MainAsyncResponse extends ErrorAsyncResponse {
// 
//     /**
//      * Delegate to handle Host + AtomicInteger outputs
//      *
//      * @param h
//      * @param i
//      */
//     void processFinish(Host h, AtomicInteger i);
// 
//     /**
//      * Delegate to handle integer outputs
//      *
//      * @param output
//      */
//     void processFinish(int output);
// 
//     /**
//      * Delegate to handle string outputs
//      *
//      * @param output
//      */
//     void processFinish(String output);
// 
//     /**
//      * Delegate to handle boolean outputs
//      *
//      * @param output
//      */
//     void processFinish(boolean output);
// 
// }


// Path: app/src/main/java/com/aaronjwood/portauthority/network/Wireless.java
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import com.aaronjwood.portauthority.async.WanIpAsyncTask;
import com.aaronjwood.portauthority.response.MainAsyncResponse;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.ByteOrder;
import java.util.Enumeration;



    /**
     * Gets the device's internal LAN IP address associated with the cellular network
     *
     * @return Local cellular network LAN IP address
     */
    public static String getInternalMobileIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en != null && en.hasMoreElements(); ) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                        return inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException ex) {
            return "Unknown";
        }

        return "Unknown";
    }

    /**
     * Gets the device's external (WAN) IP address
     *
     * @param delegate Called when the external IP address has been fetched
     */
    public void getExternalIpAddress(MainAsyncResponse delegate) {