1996-11-27 19:52:01 +00:00
|
|
|
#! /usr/bin/env python
|
1991-07-01 18:32:32 +00:00
|
|
|
|
|
|
|
# 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)
|
2000-08-25 15:38:41 +00:00
|
|
|
s.connect((host, FINGER_PORT))
|
1991-07-01 18:32:32 +00:00
|
|
|
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
|
1992-05-19 13:51:20 +00:00
|
|
|
while i < len(sys.argv) and sys.argv[i][:1] == '-':
|
1991-07-01 18:32:32 +00:00
|
|
|
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()
|