1. 程式人生 > >NNTP協議備註

NNTP協議備註

【參考資料】
【1】https://tools.ietf.org/html/rfc3977
【2】《TCP/IP 詳解 卷三》
【3】https://www.cnblogs.com/yangmingxianshen/p/7902401.html

一、基本概念
  1. NNTP(Network News Transfer Protocol) 網路新聞傳輸協議,用以在網際網路上共享新聞資料
    在這裡插入圖片描述

  2. NNTP基於TCP協議,預設埠號119

  3. NNTP也採用ASCII碼的請求、響應模式來進行協議互動,與SMTP類似

  4. NNTP服務端具備兩種模式,第一種是"READING"模式,即客戶端從服務端獲取文章或者提交該使用者建立的文章;第二種是"TRANSIT",即從一個服務端向另外一個服務端大規模的搬遷文章;

二、主要命令
會話管理相關命令

2.1 CAPABILITIES
引數: 可選的擴充套件關鍵字
功能: 客戶端獲取服務端提供的能力列表
例子:

[C] CAPABILITIES
[S] 101 Capability list:
[S] VERSION 2
[S] READER
[S] LIST ACTIVE NEWSGROUPS

2.2 MODE READER
引數: 無
功能: 觸發服務端進行模式切換,即第一章節第四條
例子:

[C] MODE READER
[S] 200 Reader mode, posting permitted
[C] MODE READER
[S] 502 Transit service only

2.3 QUIT
引數: 無
功能: 中止會話
例子:

[C] QUIT
[S] 205 closing connection
此時服務端關閉會話

釋出獲取文章相關命令

2.4 GROUP
引數: 新聞組名稱
功能: 獲取所選新聞組的基本情況,包括預估文章數量,第一和最後一篇文章的文章號
例子:

[C] GROUP misc.test
[S] 211 1234 234 567 misc.test

2.5 LISTGROUP
引數: 可選的新聞組名稱
功能: 返回該新聞組內的文章號列表
例子:

[C] GROUP misc.test
[S] 211 2000 3000234 3002322 misc.test
[C] LISTGROUP
[S] 211 2000 3000234 3002322 misc.test list follows
[S] 3000234
[S] 3000237
[S] 3000238

2.6 LAST(NEXT)
引數: 無
功能: 獲取新聞組的上(下)一篇文章
例子:

[C] GROUP misc.test
[S] 211 1234 3000234 3002322 misc.test
[C] NEXT
[S] 223 3000237 [email protected] retrieved
[C] LAST
[S] 223 3000234 [email protected] retrieved

2.7 ARTICLE
引數: 文章ID或者編號
功能: 獲取文章資訊,包含文章頭和文章主體資訊
例子:

[C] GROUP misc.test
[S] 211 1234 3000234 3002322 misc.test
[C] ARTICLE
[S] 220 3000234 [email protected]
[S] Path: pathost!demo!whitehouse!not-for-mail
[S] From: “Demo User” [email protected]
[S] Newsgroups: misc.test
[S] Subject: I am just a test article
[S] Date: 6 Oct 1998 04:38:40 -0500
[S] Organization: An Example Net, Uncertain, Texas
[S] Message-ID: [email protected]
[S]
[S] This is just a test article.
[S] .

2.8 HEADER(BODY)
引數: 文章ID或者編號
功能: 只獲取文章頭(文章體)資訊
例子: 參考ARTICLE命令

2.9 STAT
引數: 文章ID或者編號
功能: 判斷文章是否存在,類似ARTICLE但不返回具體文章資訊
例子:

[C] STAT [email protected]
[S] 223 0 [email protected]

2.10 POST
引數: 無
功能: 觸發釋出一篇文章,以 . 結尾
例子:

[C] POST
[S] 340 Input article; end with .
[C] From: “Demo User” [email protected]
[C] Newsgroups: misc.test
[C] Subject: I am just a test article
[C] Organization: An Example Net
[C]
[C] This is just a test article.
[C] .
[S] 240 Article received OK

2.11 IHAVE
引數: 文章ID
功能: 知會服務端有這樣一篇文章,如果服務端需要就返回335,之後客戶端給出這篇文章
例子:

[C] IHAVE [email protected]
[S] 335 Send it; end with .
[C] Path: pathost!demo!somewhere!not-for-mail
[C] From: “Demo User” [email protected]
[C] Newsgroups: misc.test
[C] Subject: I am just a test article
[C] Date: 6 Oct 1998 04:38:40 -0500
[C] Organization: An Example Com, San Jose, CA
[C] Message-ID: [email protected]
[C]
[C] This is just a test article.
[C] .
[S] 235 Article transferred OK

資訊相關命令

2.12 DATE
引數: 無
功能: 返回服務端時間戳
例子:

[C] DATE
[S] 111 19990623135624

2.13 NEWGROUPS (NEWNEWS)
引數: 時間戳
功能: 返回某個時間後的新聞組(新聞)
例子:

[C] NEWGROUPS 19990624 000000 GMT
[S] 231 list of new newsgroups follows
[S] alt.rfc-writers.recovery 4 1 y
[S] tx.natives.recovery 89 56 y

[C] NEWNEWS news.,sci. 19990624 000000 GMT
[S] 230 list of new articles by message-id follows
[S] [email protected]
[S] [email protected]