--- tags: 網路, telnet, powershell --- # 比Telnet更好的測試TCP連線方法 2022/06/09 平常我們要測試對方主機某個port有無開放, 我們會使用 `telnet <目標IP/DN> <PORT>` 進行測試, 如果成功的話就會一片空白不好截圖, 離開要 `Ctrl + [` 輸入 `quit` 如果失敗會得到 "無法開啟到主機的連線 / Could not open connection to the host" 的錯誤訊息 今天發現[Windows 測試 TCP 連線,比 Telnet 更好的方法](https://blog.darkthread.net/blog/ps-test-netconnection/)這篇文章 學到一個好用的指令 PowerShell 的 `Test-NetConnection` 官方完整教學 [傳送門](https://docs.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=windowsserver2022-ps) 格式如下 ```bash= Test-NetConnection -ComputerName <DN/IP> -Port <PORT> ``` 結果如下 ![](https://i.imgur.com/jwC4rTC.png)