명령줄에서 무선 네트워크를 강제로 새로 고치시겠습니까(다시 스캔하시겠습니까?)

명령줄에서 무선 네트워크를 강제로 새로 고치시겠습니까(다시 스캔하시겠습니까?)

Windows가 명령줄에서 사용 가능한 무선 네트워크를 다시 검색하도록 하려면 어떻게 해야 합니까?

(즉, GUI에서 F5를 누르는 것과 동일한 명령줄을 찾고 있습니다.)

답변1

WlanScan.exe이를 위해 작은(~2KiB) 프로그램을 작성했습니다 .

다음은 base64(32비트 버전)입니다.

TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0AAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAADJCgvEjWtll41rZZeNa2WXjWtkl4RrZZdOZDiXiGtll05kBZeMa2WXTmQ/l4xrZZdSaWNojWtllwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBFAABMAQEAnwXZXAAAAAAAAAAA4AAvAQsBBwoABgAAAAAAAAAAAAAcEwAAABAAAAAgAAAAAEAAABAAAAACAAAEAAAAAAAAAAQAAAAAAAAAACAAAAACAAAAAAAAAwAABAAAEAAAEAAAAAAQAAAQAAAAAAAAEAAAAAAAAAAAAAAAXBMAADwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALnRleHQAAAB2BAAAABAAAAAGAAAAAgAAAAAAAAAAAAAAAAAAIAAAYAAAAAAAAAAAAAAAAAAAAAAOFAAAWBQAAEYUAADqEwAA/hMAABwUAAAyFAAAAAAAAMwTAADEEwAAAAAAAFdsYW5TY2FuAAAAAFdsYW5SZWdpc3Rlck5vdGlmaWNhdGlvbgAAAAB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MAAAAAAAAAAAAAaBQAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4UAABYFAAARhQAAOoTAAD+EwAAHBQAADIUAAAAAAAAzBMAAMQTAAAAAAAAnAJleGl0AACqAF9fd2dldG1haW5hcmdzAABtc3ZjcnQuZGxsAACxAlJlbGVhc2VTZW1hcGhvcmUAAGgBR2V0TGFzdEVycm9yAAAxAENsb3NlSGFuZGxlAHoDV2FpdEZvclNpbmdsZU9iamVjdABpAENyZWF0ZVNlbWFwaG9yZVcAAJcBR2V0UHJvY0FkZHJlc3MAAEQCTG9hZExpYnJhcnlXAABLRVJORUwzMi5kbGwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=

다음과 같이 PowerShell에서 파일로 저장할 수 있습니다(Base64를 WlanScan.txt먼저 저장).

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

소스 코드는 다음과 같습니다.

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

답변2

나는 한동안 같은 것을 찾고 있었지만 불행히도 netsh 유틸리티에서 이 작업을 수행할 수 있는 항목을 찾을 수 없는 것 같습니다. 제가 생각해 낼 수 있었던 가장 좋은 해결책은 netsh 명령을 통해 인터페이스를 비활성화했다가 다시 활성화하는 것이었습니다. 인터페이스를 활성화한 후 네트워크가 나열되지 않는 약간의 지연(1~2초)이 있지만 해결하기가 그리 어렵지는 않습니다.

다음 명령을 사용하고 있습니다.

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

편집하다:"<NIC name>"네트워크 인터페이스 카드 이름을 얻는 방법 .

먼저 명령을 사용하십시오.netsh wlan show networks

WLAN이 활성화되면 다음과 같은 메시지가 나타납니다.

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

보시다시피 이 경우에는인터페이스 이름이제 WiFi 위에서 설명한 대로 진행할 수 있습니다. 예를 들어 wlan 카드를 비활성화할 수 있습니다.

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

등등. :)

답변3

파티에 조금 늦었다는 것을 알고 있지만 이를 수행하는 또 다른 방법은 wlansvc 서비스를 다시 시작하는 것입니다.

Get-Service wlansvc | Restart-Service

안타깝게도 이 작업은 관리자 권한 프롬프트에서만 수행할 수 있습니다.

답변4

현재 Windows 10 Home 버전 20H2를 실행 중이며 다음 명령을 사용하여 작업 표시줄에서 사용 가능한 네트워크 목록을 열어 강제로 다시 검색할 수 있었습니다.

explorer.exe ms-availablenetworks:

특정 네트워크에 연결하는 배치가 있습니다. 그러나 경우에 따라 해당 네트워크를 사용 가능한 네트워크로 표시하려면 다시 검색해야 합니다. 과거에는 재검색이 필요할 때 배치가 네트워크에 연결되지 못했습니다. 사용 가능한 네트워크 목록을 수동으로 연 다음 배치를 성공적으로 실행할 수 있었습니다.

이제 위의 명령이 포함되어 있으면 배치에서 사용 가능한 네트워크 목록을 열어 연결을 시도하기 전에 강제로 다시 검색합니다. 나는 그것을 광범위하게 테스트하지 않았습니다. 목록을 연 후 기다려야 한다고 생각하지만 연결을 시도하기 전에 필요할 수도 있습니다.

이 명령을 찾았습니다여기.

관련 정보