User interface AHK脚本GUI和Netstat更新延迟

User interface AHK脚本GUI和Netstat更新延迟,user-interface,cmd,command,autohotkey,netstat,User Interface,Cmd,Command,Autohotkey,Netstat,出于兴趣,我开始创建自动热键脚本GUI。 我制作了一个各种各样的诊断工具,这个工具的一个功能是使用netstat命令,以Kbps和Mbps为单位,为用户提供一个恒定的实时更新 我决定使用netstat,因为根据单独的计算机设置,适配器/连接接口可能会发生更改,导致该工具无法在所有计算机上工作 唯一的问题是使用Netstat时,更新过程中出现延迟,导致进度条数据跳回到0和实际速度之间的第四位。由于netstat数据更新的延迟,它会自行重置 我的问题是,是否有一种方法可以使用Netstat命令保持数

出于兴趣,我开始创建自动热键脚本GUI。 我制作了一个各种各样的诊断工具,这个工具的一个功能是使用netstat命令,以Kbps和Mbps为单位,为用户提供一个恒定的实时更新

我决定使用netstat,因为根据单独的计算机设置,适配器/连接接口可能会发生更改,导致该工具无法在所有计算机上工作

唯一的问题是使用Netstat时,更新过程中出现延迟,导致进度条数据跳回到0和实际速度之间的第四位。由于netstat数据更新的延迟,它会自行重置

我的问题是,是否有一种方法可以使用Netstat命令保持数据恒定和准确,或者是否有一种更有效的方法来获得所需的结果

以下是部分代码:

#SingleInstance, Force
nstFile:="C:\bytes.txt"
Process Priority,,High
OnExit, exit
Gui, Show, h450 w500, Diagnostics

Gui, Font,
Gui, Add, Text, x200 y240, Live Network Activity:
Gui, Add, Progress, x131 y260 h100 w15 Vertical clime vbytesbar backgroundgray Range0-25
Gui, Add, Text, x105 y385 h15 vbytes, Loading...
Gui, Add, Text, x80 y370, Download Speed

Gui, Add, GroupBox, x320 y231 w115 h190 cblack
Gui, Font, s6
Gui, Add, Text, x92 y353, 0  Mbps  -
Gui, Add, Text, x92 y334, 5  Mbps  -
Gui, Add, Text, x90 y314, 10 Mbps  -
Gui, Add, Text, x90 y295, 15 Mbps  -
Gui, Add, Text, x90 y276, 20 Mbps  -
Gui, Add, Text, x90 y255, 25 Mbps  -

setTimer, updateBytes, 1000

updateBytes:
    runWait %comspec% /c Netstat -e >"%nstFile%",,hide
    fileReadLine,bytesLine,% nstFile,5
    regExMatch(bytesLine,"Bytes\s+\K\d+",bytesData)
    bandwidth:=bytesData-prevBytesData
    prevBytesData:=bytesData
    guiControl,text,bytes,% bandwidth//1000 " Kbps"
    guiControl 1: , bytesbar,% bandwidth//1000000
Return

guiclose:
guiescape:
exit:
    {
    ifexist, C:\bytes.txt
    FileDelete, C:\bytes.txt
    }
    {
    exitapp
    }
return

感谢您的时间和帮助。

当您读取数据时,请使用_TickCount保存时间点,并始终将其与上次进行比较。。此外,您似乎正在查找提供商用于广告的下载速度(以千比特/秒为单位),以及大多数计算机应用程序中用于显示下载速度的下载速度(以千字节/秒为单位)。1KB=8KB,所以只需将其乘以8即可。应该是这样的: RoundcurrentSize/1024 lastSize/1024/currentSizeTick lastSizeTick/1000*8

以下是更新的代码:

#SingleInstance, Force
nstFile:="C:\bytes.txt"
Process Priority,,High
OnExit, exit
Gui, Show, h450 w500, Diagnostics

Gui, Font,
Gui, Add, Text, x200 y240, Live Network Activity:
Gui, Add, Progress, x131 y260 h100 w15 Vertical clime vbytesbar backgroundgray Range0-25000
Gui, Add, Text, x105 y385 h15 vbytes, Loading...
Gui, Add, Text, x80 y370, Download Speed

Gui, Add, GroupBox, x320 y231 w115 h190 cblack
Gui, Font, s6
Gui, Add, Text, x92 y353, 0  Mbps  -
Gui, Add, Text, x92 y334, 5  Mbps  -
Gui, Add, Text, x90 y314, 10 Mbps  -
Gui, Add, Text, x90 y295, 15 Mbps  -
Gui, Add, Text, x90 y276, 20 Mbps  -
Gui, Add, Text, x90 y255, 25 Mbps  -

setTimer, updateBytes, 1000

updateBytes:
    runWait %comspec% /c Netstat -e >"%nstFile%",,hide
    fileReadLine,bytesLine,% nstFile,5
    regExMatch(bytesLine,"Bytes\s+\K\d+",currentSize)
    currentSizeTick := A_TickCount
    speedKBs := Round((currentSize/1024-lastSize/1024)/((currentSizeTick-lastSizeTick)/1000))
    speedKBits := Round(((currentSize/1024-lastSize/1024)/((currentSizeTick-lastSizeTick)/1000))*8)
    lastSizeTick := currentSizeTick
    lastSize := currentSize
    guiControl,text,bytes,% speedKBits " Kbps"
    guiControl 1: , bytesbar,% speedKBits
Return

guiclose:
guiescape:
exit:
    {
    ifexist, C:\bytes.txt
    FileDelete, C:\bytes.txt
    }
    {
    exitapp
    }
return
我还将进度条的范围更改为0-25000,这样我们就可以节省分割部分


请注意,您需要在大多数计算机上以管理员身份运行此脚本。

最好直接使用