【问题标题】:How to get/set the IP of a hosted network如何获取/设置托管网络的 IP
【发布时间】:2017-05-07 16:12:54
【问题描述】:

我通过以下代码创建了一个虚拟 WiFi 热点,我现在需要获取它的 IP 地址,但我实际上不知道它的网络接口名称(因为没有常量名称,可能是“本地连接 *16”)。

目标是知道它的 IP 地址,因此设置托管网络的 IP 应该是解决方案之一……但最好不要涉及手动工作。

这个问题真的让我很困扰......请帮助;(

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();
        }
    }
}

【问题讨论】:

  • 我发现 2 件事可能会有所帮助:1) 托管地址值看起来像挂在“regedit.exe”中,在 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\EapolKeyIpAddress 值下“LocalAddress”但似乎不太容易检索... 2)使用 Microsoft 驱动的工具 netsh,网络连接的描述应该相同(未证明)写为“Microsoft Hosted Network虚拟适配器”请建议那些可以成为解决方案吗?

标签: c# netsh hotspot


【解决方案1】:

此解决方案涉及一个假设:使用命令netsh wlan 的虚拟热点地址将引用SYSTEM\CurrentControlSet\Services\WlanSvc\Parameters\EapolKeyIpAddress 中的注册表项LocalAddress

但我不会将其标记为答案,因为它具有不确定性。欢迎讨论或cmet。

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;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 2015-02-17
    • 2015-02-11
    • 2018-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    相关资源
    最近更新 更多