如何获取/设置托管网络的IP

How to get/set the IP of a hosted network

I created a virtual WiFi hotspot by the following code, I now need to get its IP address but I actually don't know its network interface's name (as no constant name, 'Local Connection *16' maybe).

The goal is to know its IP address so setting the hosted network's IP shall be one of solutions...but it is preferred that no manual works are involved.

This problem really stuck me......Please help ;(

private void Hotspot(string ssid, string key,bool status)
{
    ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
    processStartInfo.RedirectStandardInput = true;
    processStartInfo.RedirectStandardOutput = true;
    processStartInfo.CreateNoWindow = true;
    processStartInfo.UseShellExecute = false;
    Process process = Process.Start(processStartInfo);

    if (process != null)
    {
        if (status)
        {
            process.StandardInput.WriteLine ("");
            process.StandardInput.WriteLine("netsh wlan set hostednetwork mode=allow ssid=" + ssid + " key=" + key);
            print ("cmd: "+"netsh wlan set hostednetwork mode=allow ssid=" + ssid + " key=" + key);
            process.StandardInput.WriteLine("netsh wlan start hostednetwork");
            print ("cmd: " + "netsh wlan start hostednetwork");
            process.StandardInput.Close();
        }
        else
        {
            process.StandardInput.WriteLine ("");
            process.StandardInput.WriteLine("netsh wlan stop hostednetwork");
            print ("cmd: " + "netsh wlan stop hostednetwork");
            process.StandardInput.Close();
        }
    }
}

This solution involves an assumption: the virtual hotspot address using command netsh wlan will reference the registry key LocalAddress in SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\EapolKeyIpAddress.

Yet I won't mark it as an answer because it has uncertainty. Discussions or comments are all welcome.

private string GetVirtualHotspotIPAddress () {
    using (RegistryKey wlanKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\WlanSvc\\Parameters\\EapolKeyIpAddress")) {
        if (wlanKey != null) {
            object keyValue = wlanKey.GetValue ("LocalAddress");
            if (keyValue != null) {
                return keyValue.ToString ();
            } else {
                UnityEngine.Debug.LogError ("KEY 'LocalAddress' NOT FOUND");
                return null;
            }
        } else {
            UnityEngine.Debug.LogError ("No WLANSVC KEY FOUND");
            return null;
        }
    }
}