Try   HackMD

網路 / HTTP / RESTful 觀念及實做

History

History of the Internet
How Browsers Work?

請去看英文Denny Huang

OSI Model

英文全名:Open System Interconnection Reference Model
中文全名:開放式系統互連通訊參考模型

OSI wiki
七層( 白雪公主與七個小矮人 )

  • 第一層 實體層( Physical Layer )
  • 第二層 資料連結層( Data Link Layer )
  • 第三層 網路層( Network Layer )
  • 第四層 傳輸層( Transport Layer )
  • 第五層 會議層( Session Layer )
  • 第六層 表達層( Presentation Layer )
  • 第七層 應用層( Application Layer )

Details:

Tools

  • Wireshark
  • terminal-tool
    • dig
    • cn
    • curl
    • jq
  • python3-http.server
  • chrome extension
    • JSON Viewer

實體層( Physical Layer )

  • Network interface:網路卡
  • ipv4: 255.255.255.255
    • class a: 0.0.0.0 ~ 127.0.0.0
  • ipv6(RFC 3363):
  • Private IP (內網ip)
  • Public IP (外網ip = 公開的)
  • 打開terminal 輸入
    • ip a
    • mtr google.com 看路由
  • Port:
    • ~1024: Admin only
    • 8080:

網路層( Network Layer )

傳輸層( Transport Layer )

會議層( Session Layer )

表達層( Presentation Layer )

應用層( Application Layer )

TCP/UDP

  • Pratice: nc -lvp <port> / nc -v <host_ip><port>

    ​​​​      l: listen
    ​​​​      v: verbose 
    ​​​​      u: use UDP
    ​​​​      p: assign port
    
  • Wireshark: ip.addr == <destination_IP>
    * 限定只顯示該IP傳過來的封包內容

  • TCP : 傳輸控制協定 (Transmission Control Protocol)

    • 三向交握(three-way handshake)
    • SYN / ACK
      ​​​​​​​​    client -> SYN     -> server
      ​​​​​​​​    client <- SYN/ACK <- server
      ​​​​​​​​    cilent -> ACK     -> server
      ​​​​​​​​    cilent <-messenge -> server
      
    • 謹慎的連線
  • UDP : 用戶資料報協定(User Datagram Protocol)

    • 不謹慎,但快速的連線

    TCP 會讓你好好把話講完
    UDP 是講就對了 Denny Huang

DNS

  • 解析域名
    • ​​​​​​​  dig www.google.com 
      
      ;; ANSWER SECTION:找到 IP 可以直接連

HTTP

英文全名: Hyper Text Transfer Protocol

  • Status code
    [ Http status code list ] - neko (ΦωΦ)

    • 2xx: 成功( Success )
    • 3xx: 重新導向( Redirection )
    • 4xx: 客戶端錯誤( Client Error )
    • 5xx: 伺服器錯誤( Server Error )
  • Request headers

    • User-Agent: 可偽造
  • Response headers

  • curl command

    ​​    curl -v <IP>:<port>
    
  • Example 1:

    • Code:
    ​​​​    curl -v <IP>:<port>        
    
    • Result:
    ​​​​  GET / HTTP/1.1
    ​​​​  Host: 192.168.3.112:8080
    ​​​​  User-Agent: curl/7.65.3
    ​​​​  Accept: */*
    
  • Example 2:

    • First open python default http server ( port 8000 )
      ​​​​​​    python3 -m http.server
      

      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
      警告:不要在重要目錄開 http.server
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →

    • Then use curl
      ​​​​​​    curl -v localhost:8000
      

HTTPS

英文全名:Hyper Text Transfer Protocol Secure

  • http 是明碼傳輸

  • https 則是加密傳輸

  • Cookie / Session

    • Cookie 可僞造
      Image Not Showing Possible Reasons
      • The image file may be corrupted
      • The server hosting the image is unavailable
      • The image path is incorrect
      • The image format is not supported
      Learn More →
    • Session 推薦使用
      • Session ID is cookie

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

API

英文全名:Application Programing Interface

  • 資料傳遞

RESTful

  • GET -> 取得資料
  • POST -> 送出資料
  • PUT -> 更新資料
  • DELETE -> 刪除資料
  • And More

Data type

  • XML ( 舊式資料結構 )

    英文全名: Extensible Markup Language

    • 繁瑣
    • 很繁瑣
    • 超繁瑣
    • 神繁瑣
  • JSON

    英文全名: JavaScript Object Notation

    • recommended
    • 經過包裝
    • 類似於 Python Dict 的結構
    • Example:
      ​​​​​​​​curl -g https://api2019.coscup.org/programs.json | jq .
      

IETF / RFC

IETF ( 網際網路工程任務組 )
RFC ( 收集了有關網路相關資訊 )

吸毒貓