# 使用curl測試連接某網站的速度

curl指令本身有測速功能,搭配shell可以作為測速使用

```
curl -o /dev/null -s -w "%{time_namelookup},%{time_connect}, \
%{time_starttransfer},%{time_total}" \
https://tw.yahoo.com && echo

#------------產生數字--------------------
0.004188,0.060702, 1.931382,8.039616
```

0.004188 => DNS解析速度

0.060702 =>Client -> Sever(TCP request)

1.931382 => Server->Client(TCP Response)

8.039616 => 連線總共花費時間

了解規則後，就可以寫一個簡單的連線某網站的測速程式工具

### $1表示第一個參數，使用到條件式 if.... else.... fi

vi curlweb-speed.sh

```bash
#!/bin/bash
if [ $1 ]; then
 url=$1
else
 echo "請輸入url(exp:tw.yahoo.com)"
 read url 
fi
curl -o /dev/null -s -w \
"DNS 解析: %{time_namelookup}\n\
Client Request: %{time_connect}\n\
Server Respon: %{time_starttransfer}\n\
總花費時間: %{time_total}\n" \
"${url}"
```

![](https://529150212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh81JtaIQ84bwQqz_Wh%2F-LwWDwKp4fLWGlgBSGMs%2F-LwX3TlYocRx0KkxyqIK%2Fimage.png?alt=media\&token=22201b26-fa4d-4eeb-8a8a-74985bd19f65)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kawsing.gitbook.io/opensystem/andoid-shou-ji/untitled-4/shell-script/shi-yong-curl-ce-shi-lian-jie-mou-wang-zhan-de-su-du.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
