📜  Python -Internet协议

📅  最后修改于: 2020-11-06 06:25:29             🧑  作者: Mango


Internet协议旨在在世界各地所有与Internet连接的计算机上实现统一的地址系统,并使数据包能够从Internet的一端传输到另一端。诸如Web浏览器之类的程序应该能够在任何地方连接到主机,而无需知道每个数据包在其运行过程中所经过的网络设备的迷宫。 Internet协议有各种类别。创建这些协议是为了满足Internet中不同计算机之间不同类型的数据通信的需求。

Python有几个模块来处理这些通信场景中的每一个。这些模块中的方法和功能可以完成仅验证URL的最简单工作,也可以完成处理Cookie和会话的复杂工作。在本章中,我们将介绍用于互联网协议的最杰出的Python模块。

Protocol Python Module Name Description
HTTP urllib.request Opening the HTTP URL
HTTP urllib.response Create a reponse object for a url request
HTTP urllib.parse To break Uniform Resource Locator (URL) strings up in components like (addressing scheme, network location, path etc.),
HTTP urllib.robotparser It finds out whether or not a particular user agent can fetch a URL on the Web site that published the robots.txt file.
FTP ftplib implements the client side of the FTP protocol. You can use this to write Python programs that perform a variety of automated FTP jobs, such as mirroring other FTP servers.
POP poplib This module defines a class, POP3, which encapsulates a connection to a POP3 server to read messages from a email server
IMAP imaplib This module defines three classes, IMAP4, IMAP4_SSL and IMAP4_stream, which encapsulate a connection to an IMAP4 server to read emails.
SMTP smtplib The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP listner deamon.
Telnet telnet This module provides a Telnet class that implements the Telnet protocol to access a server thorugh teleent.

在后面的章节中将详细讨论它们中的每一个。