Force refresh (Re-Scan) drahtlose Netzwerke von der Kommandozeile?

Wie kann ich Windows zwingen, über die Befehlszeile erneut nach verfügbaren drahtlosen Netzwerken zu suchen?

(dh ich suche nach dem Befehlszeilenäquivalent zum Drücken von F5 auf der GUI.)

Author: user541686, 2015-03-14

7 answers

Ich habe jetzt schon eine Weile nach dem Gleichen gesucht, leider kann ich im netsh-Dienstprogramm anscheinend nichts dafür finden. Die beste Lösung, die ich finden konnte, bestand darin, die Schnittstelle über die netsh-Befehle zu deaktivieren und dann wieder zu aktivieren. Es gibt eine kleine Verzögerung (1-2 Sekunden) nach dem Aktivieren der Schnittstelle, in der keine Netzwerke aufgelistet sind, aber das sollte nicht zu schwer zu umgehen sein.

Ich verwende die folgenden Befehle:

netsh interface set interface name="<NIC name>" admin=disabled
netsh interface set interface name="<NIC name>" admin=enabled
netsh wlan show networks

Edit: Wie man holen Sie sich dann den "<NIC name>", dh den Namen der Netzwerkschnittstellenkarte.

Verwenden Sie zunächst den Befehl netsh wlan show networks

Wenn das WLAN aktiviert ist, erhalten Sie eine Meldung wie diese

C:\Users\user1>netsh wlan show networks

Interface name : WiFi
There are 2 networks currently visible.

SSID 1 : Cross
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP

SSID 2 : WLAN-0A8E41
    Network type            : Infrastructure
    Authentication          : WPA2-Personal
    Encryption              : CCMP

Sie sehen also, in diesem Fall lautet der Schnittstellenname WiFi Nun können Sie wie oben erläutert vorgehen, um beispielsweise die WLAN-Karte zu deaktivieren:

netsh interface set interface name="WiFi" admin=disabled

Und so weiter. :)

 11
Author: Greg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-11-01 09:38:43

Dazu habe ich ein kleines (~2 KiB) WlanScan.exe Programm geschrieben.

Hier ist die base64 (32-bit-version):

TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAA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QCTG9hZExpYnJhcnlXAABLRVJORUwzMi5kbGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

Sie können es in einer Datei von PowerShell wie folgt speichern (speichern Sie den Base64 zuerst in WlanScan.txt):

Set-Content -Path "WlanScan.exe" $([Convert]::FromBase64String($(Get-Content -Path "WlanScan.txt"))) -Encoding Byte

Hier ist der Quellcode:

#include <tchar.h>
#include <Windows.h>

#ifndef __CRT_STRINGIZE
#define __CRT_STRINGIZE(Value) #Value
#endif
#ifndef _CRT_STRINGIZE
#define _CRT_STRINGIZE(Value) __CRT_STRINGIZE(Value)
#endif

enum { WLAN_NOTIFICATION_SOURCE_ACM = 0x00000008 };
typedef enum _WLAN_NOTIFICATION_ACM { wlan_notification_acm_start, wlan_notification_acm_autoconf_enabled, wlan_notification_acm_autoconf_disabled, wlan_notification_acm_background_scan_enabled, wlan_notification_acm_background_scan_disabled, wlan_notification_acm_bss_type_change, wlan_notification_acm_power_setting_change, wlan_notification_acm_scan_complete, wlan_notification_acm_scan_fail, wlan_notification_acm_connection_start, wlan_notification_acm_connection_complete, wlan_notification_acm_connection_attempt_fail, wlan_notification_acm_filter_list_change, wlan_notification_acm_interface_arrival, wlan_notification_acm_interface_removal, wlan_notification_acm_profile_change, wlan_notification_acm_profile_name_change, wlan_notification_acm_profiles_exhausted, wlan_notification_acm_network_not_available, wlan_notification_acm_network_available, wlan_notification_acm_disconnecting, wlan_notification_acm_disconnected, wlan_notification_acm_adhoc_network_state_change, wlan_notification_acm_profile_unblocked, wlan_notification_acm_screen_power_change, wlan_notification_acm_profile_blocked, wlan_notification_acm_scan_list_refresh, wlan_notification_acm_end } WLAN_NOTIFICATION_ACM, *PWLAN_NOTIFICATION_ACM;
typedef enum _WLAN_INTERFACE_STATE { wlan_interface_state_not_ready, wlan_interface_state_connected, wlan_interface_state_ad_hoc_network_formed, wlan_interface_state_disconnecting, wlan_interface_state_disconnected, wlan_interface_state_associating, wlan_interface_state_discovering, wlan_interface_state_authenticating } WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;
typedef struct _WLAN_INTERFACE_INFO { GUID InterfaceGuid; WCHAR strInterfaceDescription[256]; WLAN_INTERFACE_STATE isState; } WLAN_INTERFACE_INFO;
typedef struct _WLAN_INTERFACE_INFO_LIST { DWORD dwNumberOfItems; DWORD dwIndex; WLAN_INTERFACE_INFO InterfaceInfo[1]; } WLAN_INTERFACE_INFO_LIST;
typedef struct _WLAN_NOTIFICATION_DATA { DWORD NotificationSource; DWORD NotificationCode; GUID InterfaceGuid; DWORD dwDataSize; void *pData; } WLAN_NOTIFICATION_DATA, *PWLAN_NOTIFICATION_DATA;
typedef void WINAPI WLAN_NOTIFICATION_CALLBACK(WLAN_NOTIFICATION_DATA *, void *);

typedef struct wlan_scan_finished_context { WLAN_INTERFACE_INFO_LIST *interface_list; HANDLE semaphore; } wlan_scan_finished_context;
static void WINAPI wlan_notification_callback(WLAN_NOTIFICATION_DATA *data, void *context)
{
    if ((data->NotificationSource | WLAN_NOTIFICATION_SOURCE_ACM) == WLAN_NOTIFICATION_SOURCE_ACM)
    {
        if (data->NotificationCode == wlan_notification_acm_power_setting_change || data->NotificationCode == wlan_notification_acm_scan_complete)
        {
            wlan_scan_finished_context *const ctx = (wlan_scan_finished_context *)context;
            if (ctx)
            {
                for (unsigned int i = 0; i != (ctx->interface_list ? ctx->interface_list->dwNumberOfItems : 0); ++i)
                {
                    if (memcmp(&ctx->interface_list->InterfaceInfo[i].InterfaceGuid, &data->InterfaceGuid, sizeof(data->InterfaceGuid)) == 0)
                    {
                        ctx->interface_list->InterfaceInfo[i].isState = (WLAN_INTERFACE_STATE)(ctx->interface_list->InterfaceInfo[i].isState | (data->NotificationCode << 16));
                    }
                }
                if (ctx->semaphore) { long prev; ReleaseSemaphore(ctx->semaphore, 1, &prev); }
            }
        }
    }
}

int _tmain(int argc, TCHAR *argv[])
{
    (void)argv;
    unsigned int result;
    if (argc > 1) { result = ERROR_INVALID_PARAMETER; }
    else
    {
        HMODULE const wlanapi = LoadLibrary(TEXT("wlanapi.dll"));
        if (wlanapi)
        {
#define X(Module, Return, Name, Params) typedef Return Name##_t Params; Name##_t *Name = (Name##_t *)GetProcAddress(Module, __CRT_STRINGIZE(Name));
            X(wlanapi, DWORD WINAPI, WlanCloseHandle, (HANDLE hClientHandle, void *pReserved));
            X(wlanapi, DWORD WINAPI, WlanEnumInterfaces, (HANDLE hClientHandle, void *pReserved, struct _WLAN_INTERFACE_INFO_LIST **ppInterfaceList));
            X(wlanapi, void WINAPI, WlanFreeMemory, (void *pMemory));
            X(wlanapi, DWORD WINAPI, WlanOpenHandle, (DWORD dwClientVersion, void *pReserved, DWORD *pdwNegotiatedVersion, HANDLE *phClientHandle));
            X(wlanapi, DWORD WINAPI, WlanRegisterNotification, (HANDLE hClientHandle, DWORD dwNotifSource, BOOL bIgnoreDuplicate, WLAN_NOTIFICATION_CALLBACK funcCallback, void *pCallbackContext, void *pReserved, DWORD *pdwPrevNotifSource));
            X(wlanapi, DWORD WINAPI, WlanScan, (HANDLE hClientHandle, const GUID *pInterfaceGuid, const struct _DOT11_SSID *pDot11Ssid, const struct _WLAN_RAW_DATA *pIeData, void *pReserved));
#undef X
            DWORD version;
            HANDLE handle = NULL;
            result = WlanOpenHandle ? WlanOpenHandle(1, NULL, &version, &handle) : ERROR_PROC_NOT_FOUND;
            if (result == ERROR_SUCCESS)
            {
                WLAN_INTERFACE_INFO_LIST *interface_list = NULL;
                result = WlanEnumInterfaces ? WlanEnumInterfaces(handle, NULL, &interface_list) : ERROR_PROC_NOT_FOUND;
                if (result == ERROR_SUCCESS)
                {
                    wlan_scan_finished_context context = { interface_list, CreateSemaphore(NULL, 0, (LONG)interface_list->dwNumberOfItems, NULL) };
                    DWORD prev;
                    unsigned int nwait = 0;
                    unsigned long const register_notification_result = WlanRegisterNotification ? WlanRegisterNotification(handle, WLAN_NOTIFICATION_SOURCE_ACM, FALSE, wlan_notification_callback, &context, NULL, &prev) : ERROR_PROC_NOT_FOUND;
                    for (unsigned int i = 0; i != interface_list->dwNumberOfItems; ++i)
                    {
                        unsigned int const result_i = WlanScan ? WlanScan(handle, &interface_list->InterfaceInfo[i].InterfaceGuid, NULL, NULL, NULL) : ERROR_PROC_NOT_FOUND;
                        interface_list->InterfaceInfo[i].isState = (WLAN_INTERFACE_STATE)(interface_list->InterfaceInfo[i].isState & 0xFFFF);
                        if (result_i == ERROR_SUCCESS) { ++nwait; }
                        else { interface_list->InterfaceInfo[i].isState = (WLAN_INTERFACE_STATE)(interface_list->InterfaceInfo[i].isState | (result_i << 16)); }
                    }
                    while (nwait > 0)
                    {
                        WaitForSingleObject(context.semaphore, INFINITE);
                        --nwait;
                    }
                    for (unsigned int i = 0; i != interface_list->dwNumberOfItems; ++i)
                    {
                        unsigned int const result_i = interface_list->InterfaceInfo[i].isState >> 16;
                        if (register_notification_result == ERROR_SUCCESS && result_i != ERROR_SUCCESS)
                        { result = result_i; }
                    }
                    if (result == ERROR_SUCCESS && register_notification_result != ERROR_SUCCESS) { result = ERROR_IO_PENDING; }
                    if (context.semaphore) { CloseHandle(context.semaphore); }
                    WlanFreeMemory ? WlanFreeMemory(interface_list) : ERROR_PROC_NOT_FOUND;
                }
                WlanCloseHandle ? WlanCloseHandle(handle, NULL) : ERROR_PROC_NOT_FOUND;
            }
        }
        else { result = (unsigned int)GetLastError(); }
    }
    return (int)result;
}
 6
Author: user541686,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-08-26 20:22:52

Die Netzwerke werden aktualisiert nur wenn ein Scan durch Ihre WLAN-Karte abgeschlossen ist. Der Befehl NETSH fordert keinen Scan an; er zeigt nur die zwischengespeicherten Ergebnisse des letzten Scans an.

Wenn Sie die Windows-Netzwerkliste in der Taskleiste öffnen, werden die Ergebnisse aktualisiert, da das Taskleisten-Netzwerktool beim Öffnen einen Scan anfordert.

Es gibt keinen Befehl NETSH, um einen solchen Scan anzufordern. Sie müssten Code schreiben, der entweder die Win32 WlanScan funktion (C# Wrapper existieren, wenn Sie das bevorzugen), oder die WinRT ScanAsync funktion.

(Angepasst / aktualisiert von der Quelle .)


Verwandte:

 4
Author: ashleedawg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2018-09-07 09:09:44

Ich weiß, dass ich etwas zu spät zur Party bin, aber eine andere Möglichkeit ist, den wlansvc-Dienst neu zu starten.

Get-Service wlansvc | Restart-Service

Leider kann dies jedoch nur über eine erhöhte Eingabeaufforderung erfolgen.

 2
Author: Josh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-05-01 18:01:13

Erweitert diese Antwort, hier ist ein Batch-Skript zur Automatisierung:

@ECHO OFF
for /f "tokens=*" %%a in ('netsh wlan show networks ^| grep -oP "Interface\s+name\s*:\s*\K(.*)"') do set "interface_name=%%a"
netsh interface set interface name=%interface_name% admin=disabled
netsh interface set interface name=%interface_name% admin=enabled
netsh wlan show networks

Stellen Sie sicher, dass Sie es als Administrator ausführen.

 0
Author: Nae,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2019-02-27 12:22:45

Ich habe den Code aus user541686 ' s Antwort genommen und in ein kleines Python-Skript mit DLLs eingefügt. Sie können es hier und ausführen python scan.py -once -logger-level=quiet um einen erneuten Scan zu erzwingen :).

BEARBEITEN

Ich wusste nicht, dass es bereits ein Python-Paket gibt, das genau das tut...

Anscheinend können Sie mit winwifi einfach wifi scan und es wird ein Force-Re-Scan durchgeführt und dann netsh

 0
Author: Shmuel Kamensky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-06-20 15:14:22

Ich verwende derzeit Windows 10 Home Version 20H2 und konnte einen erneuten Scan erzwingen, indem ich die Liste der verfügbaren Netzwerke über die Taskleiste mit diesem Befehl öffnete:

explorer.exe ms-availablenetworks:

Ich habe einen Stapel, der eine Verbindung zu einem bestimmten Netzwerk herstellt. aber manchmal ist ein Rescan erforderlich, damit dieses Netzwerk als verfügbares Netzwerk angezeigt wird. In der Vergangenheit, als ein Rescan erforderlich war, konnte mein Batch keine Verbindung zum Netzwerk herstellen. Ich könnte die Liste der verfügbaren Netzwerke manuell öffnen und dann den Stapel ausführen mit Erfolg.

Jetzt, wo der obige Befehl enthalten ist, öffnet mein Stapel die Liste der verfügbaren Netzwerke, wodurch ein erneuter Scan erzwungen wird, bevor die Verbindung versucht wird. Ich habe es nicht ausgiebig getestet. Ich stelle mir eine Wartezeit nach dem Öffnen der Liste vor, aber bevor die Verbindung versucht wird, kann dies erforderlich sein.

Ich habe diesen Befehl hier gefunden.

 0
Author: Delbert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-12-26 19:46:42