| Last change
 on this file since 392 was             2, checked in by Yuri Dario, 15 years ago | 
        
          | 
Initial import for vendor code.
 | 
        
          | 
              
Property                 svn:eol-style
 set to                 native | 
        
          | File size:
            1.2 KB | 
      
      
| Line |  | 
|---|
| 1 | #! /usr/bin/env python | 
|---|
| 2 |  | 
|---|
| 3 | # Python interface to the Internet finger daemon. | 
|---|
| 4 | # | 
|---|
| 5 | # Usage: finger [options] [user][@host] ... | 
|---|
| 6 | # | 
|---|
| 7 | # If no host is given, the finger daemon on the local host is contacted. | 
|---|
| 8 | # Options are passed uninterpreted to the finger daemon! | 
|---|
| 9 |  | 
|---|
| 10 |  | 
|---|
| 11 | import sys, string | 
|---|
| 12 | from socket import * | 
|---|
| 13 |  | 
|---|
| 14 |  | 
|---|
| 15 | # Hardcode the number of the finger port here. | 
|---|
| 16 | # It's not likely to change soon... | 
|---|
| 17 | # | 
|---|
| 18 | FINGER_PORT = 79 | 
|---|
| 19 |  | 
|---|
| 20 |  | 
|---|
| 21 | # Function to do one remote finger invocation. | 
|---|
| 22 | # Output goes directly to stdout (although this can be changed). | 
|---|
| 23 | # | 
|---|
| 24 | def finger(host, args): | 
|---|
| 25 | s = socket(AF_INET, SOCK_STREAM) | 
|---|
| 26 | s.connect((host, FINGER_PORT)) | 
|---|
| 27 | s.send(args + '\n') | 
|---|
| 28 | while 1: | 
|---|
| 29 | buf = s.recv(1024) | 
|---|
| 30 | if not buf: break | 
|---|
| 31 | sys.stdout.write(buf) | 
|---|
| 32 | sys.stdout.flush() | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | # Main function: argument parsing. | 
|---|
| 36 | # | 
|---|
| 37 | def main(): | 
|---|
| 38 | options = '' | 
|---|
| 39 | i = 1 | 
|---|
| 40 | while i < len(sys.argv) and sys.argv[i][:1] == '-': | 
|---|
| 41 | options = options + sys.argv[i] + ' ' | 
|---|
| 42 | i = i+1 | 
|---|
| 43 | args = sys.argv[i:] | 
|---|
| 44 | if not args: | 
|---|
| 45 | args = [''] | 
|---|
| 46 | for arg in args: | 
|---|
| 47 | if '@' in arg: | 
|---|
| 48 | at = string.index(arg, '@') | 
|---|
| 49 | host = arg[at+1:] | 
|---|
| 50 | arg = arg[:at] | 
|---|
| 51 | else: | 
|---|
| 52 | host = '' | 
|---|
| 53 | finger(host, options + arg) | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | # Call the main function. | 
|---|
| 57 | # | 
|---|
| 58 | main() | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.