|
6 | 6 |
|
7 | 7 | Usage: pysvr.py [port] |
8 | 8 |
|
| 9 | +For security reasons, it only accepts requests from the current host. |
| 10 | +This can still be insecure, but restricts violations from people who |
| 11 | +can log in on your machine. Use with caution! |
| 12 | +
|
9 | 13 | """ |
10 | 14 |
|
11 | 15 | import sys, os, string, getopt, thread, socket, traceback |
12 | 16 |
|
13 | | -OK_DOMAINS = [".cnri.reston.va.us", ".python.org"] |
14 | | - |
15 | | -PORT = 7585892 % 0xFFFF # == 49367 |
| 17 | +PORT = 4000 # Default port |
16 | 18 |
|
17 | 19 | def main(): |
18 | 20 | try: |
@@ -43,33 +45,19 @@ def main_thread(port): |
43 | 45 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
44 | 46 | sock.bind(("", port)) |
45 | 47 | sock.listen(5) |
| 48 | + print "Listening on port", port, "..." |
46 | 49 | while 1: |
47 | 50 | (conn, addr) = sock.accept() |
48 | 51 | thread.start_new_thread(service_thread, (conn, addr)) |
49 | 52 | del conn, addr |
50 | 53 |
|
51 | 54 | def service_thread(conn, addr): |
52 | 55 | (caddr, cport) = addr |
53 | | - try: |
54 | | - host, aliases, ipaddrs = socket.gethostbyaddr(caddr) |
55 | | - except socket.error: |
56 | | - print "Don't know hostname for", caddr |
57 | | - return |
58 | | - if '.' not in host: |
59 | | - for a in aliases: |
60 | | - if '.' in a: |
61 | | - host = a |
62 | | - break |
63 | | - else: |
64 | | - print "Only a local name (%s) for %s" % (host, caddr) |
65 | | - return |
66 | | - i = string.find(host, '.') |
67 | | - domain = string.lower(host[i:]) |
68 | | - if domain not in OK_DOMAINS: |
69 | | - print "Connection from", host, "not accepted" |
| 56 | + if caddr != socket.gethostbyname(socket.gethostname()): |
| 57 | + print "Connection from", caddr, "not accepted." |
70 | 58 | return |
71 | 59 | print "Thread %s has connection from %s.\n" % (str(thread.get_ident()), |
72 | | - host), |
| 60 | + caddr), |
73 | 61 | stdin = conn.makefile("r") |
74 | 62 | stdout = conn.makefile("w", 0) |
75 | 63 | run_interpreter(stdin, stdout) |
|
0 commit comments