Windows 7 - 通过命令行收集无线信号强度

Windows 7 - 通过命令行收集无线信号强度

我想通过命令行查看 Windows 7 中的无线信号强度(最好通过 dbm 或 %)。

这是我尝试过的:

1) 使用 MSNdis_80211_ReceivedSignalStrength 的 VBscript(但仅适用于 Vista 之前的版本)

2)使用“netsh wlan show interface”的命令行

理想情况下,我希望在一段时间内收集数据并取平均值。我知道这不可能通过直接执行命令行来实现,所以我愿意放弃这种可能性,如果我能得到仅有的信号强度百分比(%)。

答案1

经过多次内部争论,我采用了 VBScript 和命令行的组合。由于似乎不再有 WMI 方法来获取信号强度,而且我更愿意在短时间内收集信息并取平均值,因此我使用 VBScript 来执行 NETSH 并提取我需要的数据。

这绝对可以快速修改为无限重复,以便您可以带着笔记本电脑四处走动以确定不同区域的信号强度(尽管绝对不推荐,因为存在更优越的第三方软件包)。

====================================================================

dim obj_shell, obj_cmdexectestWLAN, var_line, obj_cmdexec, var_signalstrength, var_testinterval, var_counter, var_dots, var_arraycontents, var_item, var_average, var_multiplier, arr_signalstrength()
var_testinterval = 1000 'in milliseconds
var_counter = 0
var_dots = "." 'this is for a cheap progress bar

set obj_shell = wscript.createobject("WScript.Shell")
set obj_cmdexectestWLAN = obj_shell.exec("%comspec% /C netsh wlan show interfaces")
var_line = obj_cmdexectestWLAN.stdout.readline()
if instr(var_line, "not running") = 0 then

    function func_getwirelesssignalstrength()
        set obj_cmdexec = obj_shell.Exec("%comspec% /C netsh wlan show interfaces | FIND ""Signal""")
        var_line = obj_cmdexec.stdout.readline()
        var_line = replace(var_line,"Signal                 : ","")
        var_line = replace(var_line,"%","")
        var_line = trim(var_line)
        if isnumeric(var_line) then 
            func_getwirelesssignalstrength = var_line
        else
            func_getwirelesssignalstrength = "Error"
        end if
    end function

    do while var_counter < 10 '0-based. Gives us 10 samples. If you want a longer interval, you can modify both 'var_counter' at the top and this as well
        wscript.stdout.write(var_dots & chr(13))
        var_signalstrength = func_getwirelesssignalstrength()
        if isnumeric(var_signalstrength) then
            if var_counter = 0 then
                redim arr_signalstrength(0)
                arr_signalstrength(0) = var_signalstrength
            else
                redim preserve arr_signalstrength(ubound(arr_signalstrength) + 1)
                arr_signalstrength(ubound(arr_signalstrength)) = var_signalstrength
            end if
            var_counter = var_counter + 1
            var_dots = var_dots & "."
            wscript.sleep var_testinterval
        else
            wscript.echo("Error: Non-numeric value received from NETSH. Quitting...")
            wscript.quit
        end if
    loop

    for each var_item in arr_signalstrength
        var_arraycontents = var_arraycontents & var_item & ","
        var_multiplier = cint(var_multiplier) + cint(var_item)
    next
    var_average = var_multiplier/var_counter
    'wscript.echo("Multiplier:" & var_multiplier & vbcrlf & "Counter:" & var_counter & vbcrlf & "Average:" & var_average & vbcrlf & "Average Rounded:" & round(var_average,2)) 'test region to see our output in more detail
    wscript.echo("Values Received: " & var_arraycontents) 'test region to see our array contents
    wscript.echo("Signal Strength Average: " & round(var_average,2))

else
    wscript.echo("Error: WLAN Service Not Running")
    wscript.quit
end if

相关内容