curl監控站點響應時間
監控站點首頁下載時間:
curl -o /dev/null -s -w ‘%{time_total}’ http://www.miotour.com
curl -o /dev/null -s -w ‘%{http_code}’ http://www.miotour.com
curl -o /dev/null -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total} http://www.miotour.com
結果:2.547
-s 靜默輸出;沒有-s的話就是下面的情況,這是在腳本等情況下不需要的信息。
[ec2-user@ip-10-122-250-19 ~]$ curl -o /dev/null -w ‘%{time_total}’ http://www.miotour.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 67770 0 67770 0 0 19228 0 –:–:– 0:00:03 –:–:– 20705
結果:3.524
監控首頁各項時間指標:
curl -o /dev/null -s -w ‘%{time_connect}:%{time_starttransfer}:%{time_total}’ http://www.miotour.com
結果: 0.244: 1.044: 2.672
時間指標解釋 :
time_connect 建立到服務器的 TCP 連接所用的時間
time_starttransfer 在發出請求之後,Web 服務器返回數據的第一個字節所用的時間
time_total 完成請求所用的時間
在 發出請求之後,Web 服務器處理請求並開始發回數據所用的時間是
(time_starttransfer)1.044 - (time_connect)0.244 = 0.8 秒
客戶機從服務器下載數據所用的時間是
(time_total)2.672 - (time_starttransfer)1.044 = 1.682 秒
指定特定主機IP地址訪問網站
curl -x 61.135.169.105:80 http://www.baidu.com
curl -x 61.135.169.125:80 http://www.baidu.com
curl用法大全
-x 指定訪問IP與端口號
curl -x 192.168.1.1:80 http://www.miotour.com
-I 僅僅取文件的http頭部
curl -I -x 192.168.1.1:80 http://www.miotour.com
用referer做的防盜鏈,就可以使用-e來設置
curl -e “http://www.qiecuo.org” http:// www.miotour.com -v -I
-H去構造你想要的http頭部
curl -H “X-Forward-For:8.8.8.8″ http://www.miotour.com -v -I
curl反饋時間,例如連接時間,下載時間等信息
curl -w %{time_connect}:%{time_starttransfer}:%{time_total} -s -o /dev/null
將一個文件保存到硬盤上,命名爲file.html
curl -o file.html http://www.miotour.com/index.html
下載index.html文件, -O是大寫的字母
curl -O http://www.miotour.com/index.html
curl提交用戶名和密碼
curl http://name:[email protected]
curl -u name:passwd http://www.miotour.com
-b “cookie” 此參數用來構造一個攜帶cookie的請求
USER AGENT 關於瀏覽器發送的http請求信息. Curl允許用命令制定. 發送一些用於欺騙服務器或cgi的信息. 比如: curl -A 'Mozilla/3.0 (Win95; I)' http://www.nationsbank.com/ 其他命令: 'Mozilla/3.0 (Win95; I)' Netscape Version 3 for Windows 95 'Mozilla/3.04 (Win95; U)' Netscape Version 3 for Windows 95 'Mozilla/2.02 (OS/2; U)' Netscape Version 2 for OS/2 'Mozilla/4.04 [en] (X11; U; AIX 4.2; Nav)' NS for AIX 'Mozilla/4.05 [en] (X11; U; Linux 2.0.32 i586)' NS for Linux 注意:Internet Explorer能自動調節: 'Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)' MSIE for W95 Mozilla 使用User-Agent名字: 'Konqueror/1.0' KDE File Manager desktop client 'Lynx/2.7.1 libwww-FM/2.14' Lynx command line browser
PROGRESS METER The progress meter exists to show a user that something actually is happening.