網路操作指令與工具:curl, ping, telnet, nslookup


Posted by YongChenSu on 2020-12-06

curl

curl https://google.com > google.html:發一個 GET 的 request 到 google 的網址,並將其 response 存在 google.html。

start google.html:開啟 google.html,回傳 statusCode 301,代表 moved permanently,按下 here 即可導到 google.com 頁面。

curl -I https://google.com > google2.html:-I 代表只要 header,不要 body 資料。

如何使用 curl 來 post json 格式的 data?

  • 對網址發 post,格式是 json。
  • \ 是換行的意思
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{"name":"xyz","job":"none"}' \
  https://reqres.in/api/users
  • 成功建立一個 user

  • #### curl 的相關應用
    假設跑了一個 http server,可用 curl,網址是 localhost,即可測試能否順利運作。

p.s. 目前個人只學會在 bash 上使用 curl,還沒學會在 powershell 上的使用 curl 的方法。

nslookup:解析 domain 的 ip 地址

得到 github.com 的 ip 地址。

ping:測試能否送到主機,不斷送封包

telnetping 一個指定的 port

可用 telnet 來查看指定的 port 是否有開。
而 windows 預設停用 telnet 功能,故得參考這篇文章:《在 windows 上開啟 telnet 功能》將其開啟。

  1. nslookup google.com,查到 google.com 的 ip 位址。
  2. telnet 216.58.200.238 80 位址後面接 port 編號,即可查看該 port 是否有開,不過我自己這邊不管怎麼測試都出問題。

telnet 的應用

  • get /:可傳資料。
  • telnet ptt.cc:開啟 ptt

ptt 是根據 telnet 的協定。

總結

curl, ping, nslookup, telnet 是能夠偵測哪個部分有問題的實用指令

參考資源


#程式導師實驗計畫第四期 #前端







Related Posts

[day 01] this & bind: 你不能不知道的

[day 01] this & bind: 你不能不知道的

第五期直播 week15 + 期中測驗檢討

第五期直播 week15 + 期中測驗檢討

Day 130

Day 130


Comments