網絡常用命令

Table of Contents

<span class="ez-toc-title-toggle"><a href="#" class="ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle" aria-label="顯示/隱藏內容目錄"><span class="ez-toc-js-icon-con"><span class=""><span class="eztoc-hide" style="display:none;">Toggle</span><span class="ez-toc-icon-toggle-span"><svg style="fill: #999;color:#999" xmlns="http://www.w3.org/2000/svg" class="list-377408" width="20px" height="20px" viewBox="0 0 24 24" fill="none"><path d="M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z" fill="currentColor"></path></svg><svg style="fill: #999;color:#999" class="arrow-unsorted-368013" xmlns="http://www.w3.org/2000/svg" width="10px" height="10px" viewBox="0 0 24 24" version="1.2" baseProfile="tiny"><path d="M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z"/></svg></span></span></span></a></span>

IP地址的查看

Windows:

ipconfig

Linux、Mac:

ifconfig

Mac 中沒有 ip 命令,可使用brew install
ip command in Mac OS X terminal

brew install iproute2mac
ip addr

網絡連通性測試

ping命令:

ping 192.XXX.XXX.XXX

測試端口的連通性

telnet命令

mac M1需安裝telnet:

brew install telnet

測試連接google的80port如下

$ telnet www.google.com.tw 80
Trying 172.217.163.35...
Connected to www.google.com.tw.
Escape character is '^]'.

traceroute

可顯示封包在IP網路經過的路由器的IP位址。

Windwos平台指令

tracert

Linux平台指令:

traceroute
tracepath

traceroute連接到google如下:

$ traceroute www.google.com.tw
traceroute to www.google.com.tw (142.251.43.3), 64 hops max, 52 byte packets
 1  192.168.100.1 (192.168.100.1)  6.143 ms  5.137 ms  4.805 ms
 2  192.168.1.1 (192.168.1.1)  6.382 ms  7.177 ms  6.312 ms
 3  h254.s98.ts.hinet.net (168.95.98.254)  12.624 ms  7.280 ms  9.544 ms
 4  * * *
 5  203-75-90-146.hinet-ip.hinet.net (203.75.90.146)  19.812 ms  7.768 ms  6.890 ms
 6  tpdt-3308.hinet.net (168.95.81.6)  8.898 ms  7.564 ms  31.192 ms
 7  tpdt-3032.hinet.net (220.128.27.94)  14.086 ms
    tpdb-3031.hinet.net (220.128.1.102)  8.078 ms  8.284 ms
 8  * * *
 9  pcpd-3211.hinet.net (220.128.12.241)  13.199 ms
    pcpd-3211.hinet.net (220.128.13.85)  9.528 ms
    pcpd-3211.hinet.net (220.128.12.189)  7.593 ms
10  72.14.218.140 (72.14.218.140)  9.797 ms  9.633 ms  10.930 ms
11  * * *
12  209.85.243.196 (209.85.243.196)  9.198 ms
    142.251.226.170 (142.251.226.170)  28.471 ms
    216.239.48.134 (216.239.48.134)  10.657 ms
13  142.251.77.85 (142.251.77.85)  8.641 ms  17.196 ms
    tsa03s08-in-f3.1e100.net (142.251.43.3)  8.052 ms

curl命令

請求web服務的

  • -v :顯示請求詳細信息
curl quietbo.com  -v
  • -X :指定请求方式(GET or POST)
curl -X Get URL
curl -X POST URL
  • -H :指定頭部類型&Cookie
curl -H "Content-Type:application/json"
curl -H "Cookie:username=XXX" URL
  • -d :使用POST向server發送數據,下方可以省略-X POST
curl -H "Content-Type:application/json" -d '{"name":"bocky","date":"2022/1/13"}' URL -v

可參考更多網路文章,文章