File: telnet-cat.py

package info (click to toggle)
python-expect 1.0.5-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 320 kB
  • ctags: 122
  • sloc: ansic: 1,206; sh: 468; python: 157; makefile: 58
file content (36 lines) | stat: -rwxr-xr-x 782 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
#!/usr/bin/python

# cat a file from a remote site by telnet
# requires that the remote site support `uuencode -m'

# Usage:
#	telnet-cat.py <server> <login> <passwd> <remote-file>

import sys, time, binascii
from expect import *

f = popen ("telnet %s" % (sys.argv[1],), "p")
f.read ("ogin:")
f.write (sys.argv[2] + "\n")
f.read ("word:")
time.sleep (0.1)
f.write (sys.argv[3] + "\n")
# possible prompts
f.read (("#", "$", ">"))
f.write ("cat %s | uuencode -m %s\n" % (sys.argv[4], sys.argv[4]))
while 1:
    l = f.read ('\n')
    if l[:6] == "begin-":
	break
while 1:
    l = f.read ('\n')
    if l[:4] == "====":
	break;
    s = binascii.a2b_base64 (l)
    if type (s) == type (''):
	sys.stdout.write (s)
# possible prompts
f.read (("#", "$", ">"))
f.write ("exit\n")
f.read ()