[Tutor] Help debuging a small program

Mark Kels mark.kels at gmail.com
Mon Feb 21 18:36:32 CET 2005


Hi list !
Here is a small port scanner I made to practice sockets and GUI
programming ( WARNING: the program crash when scan button is clicked):

#----------Imports----------
from Tkinter import * 
import socket
#----------The result GUI window function---------
def result():
    global result_t #I made result_t global so I will be able to
insert data into it from the scan function
    r_root=Toplevel(root)
    result_t=Text(r_root)
    result_t.pack()
    
#----------Command Functions----------
# + ---Function to get the info from the gui and start the scan---
def get_info():
    result()
    host=host_e.get()
    start_port=int(start_port_e.get())
    end_port=int(end_port_e.get())
    scan(host,start_port,end_port)

# + ---The Scan---
def scan(host,start_port,end_port):
    sk=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    while start_port<=end_port:
        try:
            sk.connect((host,start_port))
        except:
            result_t.insert(END,"Port",start_port,"is CLOSED on",host,"\n")
        else:
            result_t.insert(END,"Port",start_port,"is OPENED on",host,"\n")
        start_port=start_port+1
        
#----------The main GUI window----------        
root=Tk()
Label(root,text="Host: ").grid(row=1,column=1)
host_e=Entry(root)
host_e.grid(row=1,column=2)
Label(root,text="Start port: ").grid(row=2,column=1)
start_port_e=Entry(root)
start_port_e.grid(row=2,column=2)
Label(root,text="End port: ").grid(row=3,column=1)
end_port_e=Entry(root)
end_port_e.grid(row=3,column=2)
Button(root,text="Scan",command=get_info).grid(row=5,column=1)

root.mainloop()

Why does the program crash (without any errors :-/ ) when I click the
Scan button ??

-- 
1. The day Microsoft makes something that doesn't suck is probably the
day they start making vacuum cleaners.
2. Unix is user friendly - it's just picky about it's friends.
3. Documentation is like sex: when it is good, it is very, very good.
And when it is bad, it is better than nothing. - Dick Brandon


More information about the Tutor mailing list