See All Titles |
![]() ![]() Newsgroups—Telnet and GopherThe nntplib module implements a low-level interface to the client side of the NNTP (Network News Transfer Protocol) protocol—a service mostly known for providing newsgroups. This protocol is text-based because all the communication between the client and the server uses ASCII text. This protocol is also used to exchange Usenet news articles between servers. Newsgroups are organized hierarchically, according to their levels, which are separated by dots. In comp.lang.python for example, comp defines computer-related newsgroups and lang defines that it refers to computer languages. It is shown as follows: 1: import nntplib 2: import string 3: ServerAlias = "news.lessaworld.com" 4: NewsGroup = "comp.lang.opensource" 5: Keyword = raw_input("Enter keyword to search: ") 6: NewsServer = nntplib.NNTP(ServerAlias) 7: r, count, firstmsg, lastmsg, name = NewsServer.group(NewsGroup) 8: r, messages = NewsServer.xover(first, last) 9: for id, subject, author, date, msgid, refer, size, lines in messages: 10: if string.find(subject, Keyword) >= 0: 11: r, id, msgid, msgbody = NewsServer.article(id) 12: print "Author: %s - Subject: %s - Date: %s\ n" % } 13: (author, subject, date) 14: print "<-Begin Message->\ n" 15: print msgbody 16: print "<-End Message->\ n" Line 6: Creates the NNTP object and connects to a NewsServer. Line 7: Selects the newsgroup that you want to read. Check out Python's documentation for more details about this module at the following URLs: http://www.python.org/doc/lib/nntp-objects.html and http://www.python.org/doc/lib/module-nntplib.html The telnetlib module implements a client for the telnet protocol. This protocol is used to connect to remote computers, usually via the port (23). After you have established your telnet connection, you can execute commands remotely on that computer through your telnet interface. The commands you use are UNIX commands, such as ls, cd, pine, elm, talk, rm provided that the telnet server is running on a UNIX box. If you have a windows telnet server, you would probably have an MS-DOS style command prompt. The protocol is shown in the following: import telnetlib hostserver = "http://www.lessaworld.com" newline = "\ n" username = "user02" + newline password = "qwerty0987" + newline telnet = telnetlib.Telnet(hostserver) telnet.read_until("login: ") telnet.write(username) telnet.read_until("Password: ") telnet.write(password) while 1: command = raw_input("[shell]: ") telnet.write(command) if command == "exit": break telnet.read_all() For implementation details, you can check out the official documentation at http://www.python.org/doc/lib/module-telnetlib.html and http://www.python.org/doc/lib/telnet-objects.html Gopher provides a distributed information delivery system around which a world campus-wide information system (CWIS) can readily be constructed. While providing a delivery vehicle for local information, Gopher facilitates access to other Gopher and information servers throughout the world. The gopherlib module is a minimal client side implementation of the Gopher protocol. Although Gopher is an old protocol, it is still used by many universities. Gopher provides an hierarchical interface for both texts and binaries. This module is used by the urllib module to handle URLs that use the Gopher protocol. The gopherlib module is shown as follows: import gopherlib GopherServer = "gopher.lessaworld.com" directory = gopherlib.send_selector("1/", GopherServer) for topic in gopherlib.get_directory(directory): print topic Check out the official documentation for more details: http://www.python.org/doc/lib/module-gopherlib.html
|
Index terms contained in this section. (dots)campus-wide information system (CWIS) CWIS (campus-wide information system) dots (.) Gopher Gopher protocol gopherlib module modules gopherlib nntplib telnetlib Network News Transfer Protocol (NNTP) networking newsgroups newsgroups NNTP (Network News Transfer Protocol) nntplib module periods (.) protocols Gopher Network News Transfer (NNTP) Telnet telnetlib module |
© 2002, O'Reilly & Associates, Inc. |