[Tutor] Help debuging a small program

Kent Johnson kent37 at tds.net
Tue Feb 22 20:27:07 CET 2005


Mark Kels wrote:
> On Mon, 21 Feb 2005 13:21:35 -0500, Kent Johnson <kent37 at tds.net> wrote:
> 
>>How far does it get? How do you know?
>>
>>I would put some debug print statements in. Also you should call sk.close() in the else clause of
>>scan(). Finally, I don't think you will see any output in the result window until get_info()
>>returns; you have to give some time to mainloop() for it to be able to trigger the updates.
> 
> I don't understand how to prevent the program from crashing right now...
> I'll deal with other bugs when I'll finish this one :)
> So, why does the program crashes and how can I prevent it ??

I don't know either. Put some print statements in so you can see how far it is getting. Or you might 
be able to run it with the IDLE debugger, I don't know if that works to debug Tk programs.

I would rewrite scan() like this and see what you get:

def scan(host,start_port,end_port):
     print 'Scanning', host, start_port, end_port
     sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     while start_port<=end_port:
         try:
             print 'Trying port', start_port
             sk.connect((host,start_port))
         except:
             import traceback
             trackback.print_exc()
             result_t.insert(END,"Port",start_port,"is CLOSED on",host,"\n")
         else:
             print "Port",start_port,"is OPENED"
             result_t.insert(END,"Port",start_port,"is OPENED on",host,"\n")
         start_port=start_port+1

Actually, I just tried the program and it didn't crash at all. I searched from port 80 to 90 and it 
returned correct info. It takes a long time, though - the timeout on the connection seems to be 
pretty long. It doesn't show any output until it is done, and the UI is dead, so it seems crashed 
but it isn't.

Kent

> 
> Thanks !!
> 




More information about the Tutor mailing list