网线插不好降速后续:写了个检测工具

讨论 未结 5 63
phithon phith0n
phithon phith0n LV6 2022年4月17日 11:48 发表
<p>这个帖子的后续:<a href="https://www.v2ex.com/t/847384" rel="nofollow">https://www.v2ex.com/t/847384</a>。起因是昨天发现网络协商的速度只有 100Mbps 了,重新插网线才解决。</p> <p>评论区很多热心网友提供了建议,但我还是不能确定是网线、接口本身的问题还是没插好导致的,所以我需要观察一段时间。</p> <p>那么问题来了,100Mbps 其实也能正常上网、看视频等,很有可能降速了我第一时间发现不了。</p> <p>于是我用自己拙劣的 Powershell 基础写了个小脚本用来检查当前网速是 Gbps 还是 Mbps:</p> <pre><code class="language-powershell">Import-Module BurntToast $speed = Get-NetAdapter -Name Ethernet | Format-Wide -Property linkSpeed | Out-String $speed = $speed -replace '(^\s+|\s+$)','' if ($speed -Like '*Gbps*') { Write-Output 'info: check normally' } elseif ($speed -Like '*Mbps*') { $info = 'warning: network speed has been downgraded to ' + $speed Write-Output $info New-BurntToastNotification -Text $info } else { Write-Output 'error: failed to get network speed' } </code></pre> <p>里面用了这个模块<a href="https://github.com/Windos/BurntToast" rel="nofollow">https://github.com/Windos/BurntToast</a>,如果发现 Ethernet 的网速变成 Mbps ,就发一个通知。</p> <p>然后这个脚本需要让它定时运行,所以我加了个计划任务。</p> <p>Security Options 设置成系统级,这样运行的时候不会有蓝色 Powershell 窗口弹出:</p> <p><img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i.v2ex.co/BFCdhr3Z.png"></p> <p>Trigger 增加一个 daily 任务,然后 repeat 改成 1 hour ,一小时运行一次:</p> <p><img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i.v2ex.co/ihYIBECz.png"></p> <p>Actions 增加 Powershell 运行的命令,别忘了加<code>-ExecutionPolicy RemoteSigned</code>:</p> <pre><code>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -File check-speed.ps1 </code></pre> <p><img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i.v2ex.co/72z6KJk6.png"></p> <p>最后 Conditions 设置成联网后,或者连特定的网络时才会检查:</p> <p><img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i.v2ex.co/4wLo9TQF.png"></p> <p>如果检查出问题,右下角就会弹出一个 Notification:</p> <p><img alt="" class="embedded_image" loading="lazy" referrerpolicy="no-referrer" rel="noreferrer" src="https://i.v2ex.co/2f9K8SNm.png"></p> <p>后面就静待了,看看还会不会出现降速的问题~希望脚本没写出 Bug😂</p>
收藏(0)  分享
相关标签: 灌水交流
注意:本文归作者所有,未经作者允许,不得转载
5个回复
  • phithon
    2022年4月17日 14:19
    可以的,改下 Get-NetAdapter 的 Name
    0 0
  • hxsf
    2022年4月17日 14:19
    关掉自动协商,强制 1G ,不能 1G 的话,网络就会断开。
    0 0