Reputation: 496
(let's say i use local gateway for ip and 23 for port, so telnetting into my router)
import socket
q = socket.socket()
q.connect(ip, port)
data = q.recv(1024)
print data
(some alt-code gibberish or whatever on the first line)
RT v24-sp2 std (c) 2012 NewMedia-NET GmbH
Release: 03/21/12 (SVN revision: 18795)
DD-WRT login:
(just the alt-code gibberish from the first line)
Any advice regarding why this is happening and how to correct it would be greatly appreciated.
Thanks,
Andrew
Upvotes: 0
Views: 4025
Reputation: 22261
When running the commands slowly one at a time, your router has time to send everything it's planning to send before you have a chance to invoke q.recv(1024)
.
When you run it from a script, the commands execute in quick succession. When the script executes q.recv(1024)
, the router has only managed to send some data, not all of it.
Since you do not use a loop to go back and try reading more data, that's the end, you will not receive (or print) any more data.
(By the way, what in the world is "alt-code gibberish"? What you should be getting here is some binary data that's part of the telnet protocol negotiation.)
Upvotes: 1