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

 

 

沒有留言:

VMware VCenter 6.7設定Log Server失敗

VMware VCenter 6.7設定Log Server失敗 使用vCenter 6.7 設定步驟 開啟 VAMI 介面:開啟瀏覽器,輸入 https://<您的vCenter_IP>:5480。  登入:使用 root 帳號及其密碼登入。  進入 Syslog:...