blob: e8b9ed2b08c5b90fc6efaa255538ee4a370a0e29 [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossum22825e81991-07-01 18:32:32 +00002
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
11import sys, string
12from socket import *
13
14
15# Hardcode the number of the finger port here.
16# It's not likely to change soon...
17#
18FINGER_PORT = 79
19
20
21# Function to do one remote finger invocation.
22# Output goes directly to stdout (although this can be changed).
23#
24def finger(host, args):
Tim Peterse6ddc8b2004-07-18 05:56:09 +000025 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()
Guido van Rossum22825e81991-07-01 18:32:32 +000033
34
35# Main function: argument parsing.
36#
37def main():
Tim Peterse6ddc8b2004-07-18 05:56:09 +000038 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)
Guido van Rossum22825e81991-07-01 18:32:32 +000054
55
56# Call the main function.
57#
58main()