[Tutor] telnet read_until problems
Bob Gailer
bgailer at alum.rpi.edu
Tue Feb 13 03:04:15 CET 2007
Chris Hallman wrote:
>
> I've written a program that tests ISDN dial backup at 1,000 locations.
> I've broken up the logic into server functions within a threading
> class (i.e. logon, get interfaces, get dial string, etc.). At 999
> locations, the following code extract the first of three dial strings:
>
> def GetDialString(self):
> """ This function extracts the dial string."""
> self.tn.write("term len 0\n")
> self.tn.expect([self.host.upper() + "#"], 7)
> self.tn.write("sh dialer | i Default\n")
> self.data = self.tn.read_until(self.host.upper() + "#", 7)
> print self.data
> match = re.search("\d\d\d\d\d\d\d\d\d\d\d+", self.data)
> if match is not None:
> rc = match.group()
> else:
> rc = "missing"
> return rc
>
> One location doesn't return it's dial string. In Idle, the output is:
>
> >>> print data
> sh dialer | i Default
> 17002111000 1 0 8w2d successful
> Default
> 17002111002 0 0 never -
> Default
> 17002111001 1 0 never -
> Default
> J07MR3640#
>
> The "print data" statement yields:
>
> term len 0
> J07MR3640#
>
> I've run a packet capture and I see the data coming back every time. I
> don't understand why it works fine for 999 out of 1,000 locations. Any
> suggestions?
Sorry but I find the above confusing. The best guess I can make is that
the 5 lines following >>> print data is the packet capture, and the 2
lines following "yields:" is the subset of the packet capture that comes
into self.data. Is this true? If so are you asking why
self.tn.read_until(self.host.upper() + "#", 7) does not get all the packet?
--
Bob Gailer
510-978-4454
More information about the Tutor
mailing list