File: finger.py

package info (click to toggle)
xtalk 1.3-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 112 kB
  • ctags: 140
  • sloc: python: 757; makefile: 54; sh: 18
file content (39 lines) | stat: -rwxr-xr-x 944 bytes parent folder | download
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
#!/usr/bin/python

import regex, socket, sys
from Tkinter import *

error = "fingerError"

def finger(user, host):
    fingerPort = socket.getservbyname('finger', 'tcp')
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((host, fingerPort))
    fp = sock.makefile("r+")
    fp.write(user + "\r\n")
    fp.flush()
    return fp.read()

def parseQuery(query):
    rx = regex.compile("^\([^ \t@]+\)?\(@\([^ \t]+\)\)?$")
    if rx.match(query) > 0:
	user, host = rx.group(1, 3)
	if not user: user = ""
	if not host: host = "localhost"
	return (user, host)
    else:
	raise error, "Bad address format."

class Finger(Frame):
    def __init__ 
    
if __name__ == '__main__':
    if len(sys.argv) > 1:
	for query in sys.argv[1:]:
	    user, host = parseQuery(query)
	    print "[%s]" % host
	    print finger(user, host)
    else:
	print "[localhost]"
	print finger("", "localhost")