File: finger.py

package info (click to toggle)
python2.1 2.1.3dfsg-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 38,028 kB
  • ctags: 64,228
  • sloc: python: 186,023; ansic: 184,754; xml: 43,435; sh: 12,381; makefile: 3,523; perl: 3,108; lisp: 2,460; cpp: 106; sed: 2
file content (58 lines) | stat: -rwxr-xr-x 1,137 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env 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()