2022年1月7日 星期五

使用powershell,測試 TCP 連線,比 Telnet 更好的方法

Windows powershell 測試 TCP 連線,比 Telnet 更好的方法。

過去以來,要測試某個 IP 的某個 Port 通不通,我最常用的做法是開 Cmd (命令提示字元),下指令 telnet server_ip port_no,如果失敗會得到 "無法開啟到主機的連線 / Could not open connection to the host" 的錯誤訊息,如果成功則會畫面一黑等你輸入指令:

用這種做法檢測 TCP 連線還算簡便,美中不足之處是成功是畫面清空一面黑,只能肉眼觀察沒法擷圖當作呈堂證供,而進入輸入指令模式,想結束得 Ctrl-[ 輸入 quit 或設法讓伺服器主動斷線。

最近我學到更好的 TCP Port 檢測方法 - PowerShell Test-NetConnection。

資料來源: blog.darkthread.net
 

PS C:\> Test-NetConnection -computerName www.google.com -Port 9527
警告: TCP connect to (172.217.160.68 : 9527) failed


ComputerName : www.google.com
RemoteAddress : 172.217.160.68
RemotePort : 9527
InterfaceAlias : 乙太網路
SourceAddress : 192.168.1.155
PingSucceeded : True
PingReplyDetails (RTT) : 3 ms
TcpTestSucceeded : False

 

PS C:\> Test-NetConnection -computerName www.google.com -Port 443


ComputerName : www.google.com
RemoteAddress : 172.217.160.68
RemotePort : 443
InterfaceAlias : 乙太網路
SourceAddress : 192.168.1.155
TcpTestSucceeded : True

 

PS C:\> Test-NetConnection -computerName 172.217.160.68 -Port 443


ComputerName : 172.217.160.68
RemoteAddress : 172.217.160.68
RemotePort : 443
InterfaceAlias : 乙太網路
SourceAddress : 192.168.1.155
TcpTestSucceeded : True

 

 

沒有留言:

Windows Server因為Windows update後,導致自動重啟或是自動重新開機

從 Windows Server 2016 開始,微軟確實改變了更新機制,使其行為更接近消費端的 Windows 10,這在伺服器管理上引發了不少討論。 以下為您確認微軟在 Windows Server 2016 上的具體行為: 1. 預設行為:自動下載與安裝 在 Windows...