diff options
author | Guido van Rossum <guido@python.org> | 1991-07-01 18:32:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1991-07-01 18:32:32 (GMT) |
commit | 22825e86f6e13a4d84822ae9ee7c8a807259f37d (patch) | |
tree | a773c67d671fc73801ebc372e0cf6451192aacb5 /Demo/sockets/finger.py | |
parent | 2fa5a7fc00a726c119f7626c702ffb7fa464b25b (diff) | |
download | cpython-22825e86f6e13a4d84822ae9ee7c8a807259f37d.zip cpython-22825e86f6e13a4d84822ae9ee7c8a807259f37d.tar.gz cpython-22825e86f6e13a4d84822ae9ee7c8a807259f37d.tar.bz2 |
Initial revision
Diffstat (limited to 'Demo/sockets/finger.py')
-rwxr-xr-x | Demo/sockets/finger.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Demo/sockets/finger.py b/Demo/sockets/finger.py new file mode 100755 index 0000000..8aa0535 --- /dev/null +++ b/Demo/sockets/finger.py @@ -0,0 +1,58 @@ +#! /usr/local/python + +# Python interface to the Internet finger daemon. +# +# Usage: finger [options] [user][@host] ... +# +# If no host is given, the finger daemon on the local host is contacted. +# Options are passed uninterpreted to the finger daemon! + + +import sys, string +from socket import * + + +# Hardcode the number of the finger port here. +# It's not likely to change soon... +# +FINGER_PORT = 79 + + +# Function to do one remote finger invocation. +# Output goes directly to stdout (although this can be changed). +# +def finger(host, args): + s = socket(AF_INET, SOCK_STREAM) + s.connect(host, FINGER_PORT) + s.send(args + '\n') + while 1: + buf = s.recv(1024) + if not buf: break + sys.stdout.write(buf) + sys.stdout.flush() + + +# Main function: argument parsing. +# +def main(): + options = '' + i = 1 + while i < len(sys.argv) and sys.argv[i][:1] = '-': + options = options + sys.argv[i] + ' ' + i = i+1 + args = sys.argv[i:] + if not args: + args = [''] + for arg in args: + if '@' in arg: + at = string.index(arg, '@') + host = arg[at+1:] + arg = arg[:at] + else: + host = '' + finger(host, options + arg) + + +# Call the main function. +# +main() |