使用 PsPing & PaPing 進行 TCP 端口連通性測試


PsPing & PaPing 介紹

通常,我們測試數據包能否通過 IP 協議到達特定主機時,都習慣使用 ping 命令。工作時 ping 向目標主機發送一個 IMCP Echo 請求的數據包,並等待接收 Echo 響應數據包,通過響應時間和成功響應的次數來估算丟包率和網絡時延。但是在 Azure 中,ICMP 包無法通過防火牆和負載均衡器,所以不能直接使用 ping 來測試 Azure 中的虛擬機和服務的連通性(VPN 和 Express Route 通道中的流量不經過負載均衡器,所以只要鏈路上的防火牆允許 ICMP 包傳遞,ping 依然可用)。

為了在 Azure 中進行連通性測試,例如測試 RDP、SSH 端口可用性,或者 HTTP、HTTPS 服務穩定性,甚至測試從 Azure 向外部服務的連接,我們都推薦使用 PsPing 或 PaPing。PsPing 是微軟 PSTools 工具套件中的其中一個命令。除了ICMP ping 測試,它主要用來測試 TCP 端口的連通性,還可以測試 TCP/UDP 網絡時延和帶寬。不過, PsPing 只能在 Windows 中運行。如果您需要在 Linux 中發起 TCP 端口連通性和網路時延的測試,可以使用 PaPing 。PaPing 是一個跨平台的開源工具。它的功能相對 PsPing 而言更簡單,只支持 TCP 端口的相關測試,不支持 UDP 端口的測試。

PsPing

下載和安裝

PsPing 下載地址包含了它的詳細使用方法,若有需要可以查看此頁面上的幫助信息。下載完后,可以單獨將 psping.exe 命令解壓出來放在任意路徑,然后從命令提示符來運行。當然,您也可以將整個壓縮包解壓到指定的路徑來獲取壓縮包內完整的 PSTools 工具套件。

使用方法

打開命令行提示符窗口,進入到 psping.exe 所在的目錄,就可以運行 PsPing 了。如前文所述,PsPing 支持的測試方法有很多,這里我們主要介紹針對 TCP 端口的連通性測試。最簡單的測試方法就是直接在 psping.exe 命令后面加上要測試的主機名和端口,然后執行。這里以從 Azure 內部測試 www.azure.cn 的 TCP-80 端口為例,命令為psping.exe www.azure.cn:80

C:\Tools>psping www.azure.cn:80

PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

TCP connect to 116.211.251.197:80:
5 iterations (warmup 1) ping test:
Connecting to 116.211.251.197:80 (warmup): from 10.91.1.4:51413: 34.69ms
Connecting to 116.211.251.197:80: from 10.91.1.4:51414: 29.11ms
Connecting to 116.211.251.197:80: from 10.91.1.4:51415: 30.56ms
Connecting to 116.211.251.197:80: from 10.91.1.4:51416: 49.02ms
Connecting to 116.211.251.197:80: from 10.91.1.4:51417: 43.84ms

TCP connect statistics for 116.211.251.197:80:
  Sent = 4, Received = 4, Lost = 0 (0% loss),
  Minimum = 29.11ms, Maximum = 49.02ms, Average = 38.13ms

我們可以看到,PsPing 獲取到 www.azure.cn 的IP為 175.25.168.95。隨后進行了一次熱身測試,熱身測試的目的在於使正式的測試數據更准確。最終統計結果只計算 4 次正式測試數據。其中,統計結果第一行包含發送請求的次數,接收到回應的次數,連接丟失的次數以及丟失百分比。第二行為最小、最大以及平均的響應時延。 我們還可以在命令行中添加參數來定義 PsPing 進行測試的方式。以下為 PsPing 進行 TCP 連接測試時所支持的參數:

-t 類似於 ICMP 的長 ping 測試,直到按下 Ctrl+C 停止測試,並顯示統計結果;
-n 指定測試次數。還可以指定測試的時間長度,以秒為單位,使用時在數字后加上 s,例如“10s”;
-i 每次測試的間隔,默認為 1 秒。還可以指定為 0 來進行快速 ping 測試;
-w 熱身次數,默認為 1 次;
-q 測試過程中不輸出結果,結束后顯示統計結果;
-h 將時延結果統計為直方圖打印(默認打印 20行),也可以指定結果行數,比如 -h 10,指定 10 行;另一種使用方法是統計自定義時延,比如 -h "65,70",結果將統計時延分別為 65 和 70 毫秒的次數;
-4 強制使用 IPv4;
-6 強制使用 IPv6;

更多時候,我們指定測試次數,例如 500 次、1000 次。待測試結束后查看統計結果,根據連接成功率和 TCP 響應時延來判斷被檢測服務的可用性和穩定性。不過,由於是測試 TCP 連接,測試時不排除被測試服務有一定的防護機制,對連續、大量的 TCP 連接采取拒絕服務或者限制服務,導致測試結果看起來很槽糕。這需要測試人對被測試服務有一定的了解。

我們還是以測試 www.azure.cn 為例,測試 500 次連接的命令為 psping.exe -n 500 www.azure.cn:80

C:\Tools>psping -n 500 www.azure.cn:80

PsPing v2.10 - PsPing - ping, latency, bandwidth measurement utility
Copyright (C) 2012-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

TCP connect to 175.25.168.95:80: 501 iterations (warmup 1) ping test: Connecting to 175.25.168.95:80 (warmup): from 10.91.1.4:51531: 2.28ms Connecting to 175.25.168.95:80: from 10.91.1.4:51532: 1.86ms Connecting to 175.25.168.95:80: from 10.91.1.4:51533: 2.67ms .................... Connecting to 175.25.168.95:80: from 10.91.1.4:52029: 1.90ms Connecting to 175.25.168.95:80: from 10.91.1.4:52030: 2.69ms Connecting to 175.25.168.95:80: from 10.91.1.4:52031: 2.69ms Connecting to 175.25.168.95:80: from 10.91.1.4:52032: 2.39ms

TCP connect statistics for 175.25.168.95:80:
  Sent = 500, Received = 500, Lost = 0 (0% loss),
  Minimum = 1.49ms, Maximum = 4.72ms, Average = 2.35ms

PaPing

下載和安裝

PaPing 下載網址,其中 32 位 Linux 對應的壓縮包為 paping_1.5.5_x86_linux.tar.gz,64 位的 Linux 對應的壓縮包為 paping_1.5.5_x86-64_linux.tar.gz。下載完成后,直接解壓到任意路徑,就可以直接執行了。

以 64 位 Linux 為例:

#cd ~
#wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/paping/paping_1.5.5_x86-64_linux.tar.gz
#tar zxvf paping_1.5.5_x86-64_linux.tar.gz

使用方法

PaPing 的使用方法與 PsPing 非常相似,甚至更簡單,功能更單一。PaPing 所支持的參數如下:

-p, --port N 指定被測試服務的 TCP 端口(必須);
--nocolor 屏蔽彩色輸出;
-t, --timeout   指定超時時長,單位為毫秒,默認值為 1000;
-c, --count N   指定測試次數。

默認 PaPing 的結果會根據 Shell 的色彩配置輸出不同顏色。如果您將結果通過“>”輸出到文件,建議使用 --nocolor 參數。這樣輸出的文件中就不會包含色彩相關的字符,更方便后期處理。

同樣以測試 500 次對 www.azure.cn 的 80 端口的 TCP 連接為例,跳轉到 PaPing 所在的路徑后,執行 ./paping -p 80 -c 500 www.azure.cn

[kyle@centos7 ~]$ ./paping -p 80 -c 500 www.azure.cn
paping v1.5.5 - Copyright (c) 2011 Mike Lovell

Connecting to 1stcncloud.dtwscachev290.ourwebcdn.com [112.17.28.203] on TCP 80:

Connected to 112.17.28.203: time=8.26ms protocol=TCP port=80
Connected to 112.17.28.203: time=7.48ms protocol=TCP port=80
Connected to 112.17.28.203: time=9.62ms protocol=TCP port=80
Connected to 112.17.28.203: time=8.54ms protocol=TCP port=80
....................

Connected to 112.17.28.203: time=9.59ms protocol=TCP port=80
Connected to 112.17.28.203: time=11.79ms protocol=TCP port=80
Connected to 112.17.28.203: time=8.14ms protocol=TCP port=80
Connected to 112.17.28.203: time=10.94ms protocol=TCP port=80
Connected to 112.17.28.203: time=22.35ms protocol=TCP port=80

Connection statistics:
    Attempted = 500, Connected = 500, Failed = 0 (0.00%)
Approximate connection times:
    Minimum = 6.46ms, Maximum = 25.00ms, Average = 12.40ms




Troubleshooting with the Windows Sysinternals Tools

https://docs.microsoft.com/zh-cn/sysinternals/learn/troubleshooting-book

Table of Contents

  • Part I: Getting started
    • Chapter 1 Getting started with the Sysinternals utilities
    • Chapter 2 Windows core concepts
  • Part II: Usage guide
    • Chapter 3 Process Explorer
    • Chapter 4 Autoruns
    • Chapter 5 Process Monitor
    • Chapter 6 ProcDump
    • Chapter 7 PsTools
    • Chapter 8 Process and diagnostic utilities
    • Chapter 9 Security utilities
    • Chapter 10  Active Directory utilities
    • Chapter 11  Desktop utilities
    • Chapter 12  File utilities
    • Chapter 13  Disk utilities
    • Chapter 14  Network and communication utilities
    • Chapter 15  System information utilities
    • Chapter 16  Miscellaneous utilities
  • Part III: Troubleshooting — "The Case of the Unexplained..."
    • Chapter 17  Error messages
    • Chapter 18  Crashes
    • Chapter 19  Hangs and sluggish performance
    • Chapter 20  Malware
    • Chapter 21  Understanding system behavior
    • Chapter 22  Developer troubleshooting


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM