Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old November 30th, 2003, 12:21 AM
Gerardoj's Avatar
Gerardoj Gerardoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Somewhere over the Rainbow
Posts: 128 Gerardoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 54 m 28 sec
Reputation Power: 5
Adding code to GUI

Hi, I would like to know why doesnt works my below code?, dont show any error message! Thanks.

Code:
       def port(self):
    	   
        try:
	   t = tkSimpleDialog.askstring('DATA',               
                                     ENTER IP or HOST:', 
                                     parent=self.TextBox)  
           host = t[1]
           maxport = int(t[2]) + 1

           for port in xrange(1, maxport):
               s = socket(AF_INET, SOCK_STREAM)
               try:
                  s.connect((host, port))
                  self.TextBox.insert(Tkinter.END,"Port %d is open" % port)
               except error:
                   continue
    	except IndexError:
         self.TextBox.insert(Tkinter.END,  "Usage: %s <ip address> <max port>" % t[0])
     	except ValueError:
         self.TextBox.insert(Tkinter.END, "Port must be a valid integer")
     	except Exception, e:
         print e

Reply With Quote
  #2  
Old November 30th, 2003, 06:55 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I'd love to tell you but it seems like we've only got a small bit of your actual program here, could you attach the whole scrript?

The reason your not getting an error message would be because you wrapped your code up inside try-except blocks which are kinda like walls errors can't pass though.

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 30th, 2003, 12:34 PM
Gerardoj's Avatar
Gerardoj Gerardoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Somewhere over the Rainbow
Posts: 128 Gerardoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 54 m 28 sec
Reputation Power: 5
Thanks for your reply, here is my whole script

Code:
import Tkinter
import tkFileDialog
import tkSimpleDialog
import string
from socket import *


TEXT_FILE_TYPES=[("PRO Scanner Files","scn"),("All files","*")] 

class Scanner:
    def __init__(self):        
        self.FileName=None
        self.CreateWidgets()

    def CreateWidgets(self):
        self.root=Tkinter.Tk()
        self.root.title("New file")
        MainFrame=Tkinter.Frame(self.root)        
 
        MenuFrame=Tkinter.Frame(self.root)
        MenuFrame.pack(side=Tkinter.TOP,fill=Tkinter.X)
        FileMenuButton=Tkinter.Menubutton(MenuFrame,
            text="File",underline=0)
        FileMenuButton.pack(side=Tkinter.LEFT,anchor=Tkinter.W)
        FileMenu=Tkinter.Menu(FileMenuButton,tearoff=0)
        FileMenu.add_command(label="New",underline=0,
            command=self.port)        
        FileMenuButton["menu"]=FileMenu        
        # Create the main text field:
        self.TextBox=Tkinter.Text(MainFrame,background="white",foreground="black")
        self.TextBox.pack(fill=Tkinter.BOTH,expand=Tkinter.YES)
        # Pack the top-level widget:
        MainFrame.pack(fill=Tkinter.BOTH,expand=Tkinter.YES)

    def port(self):
    	   
        try:
	   t = tkSimpleDialog.askstring('INGRESO DE DATOS',               
                                     'Ingrese la IP o HOST:', 
                                     parent=self.TextBox)  
           host = t[1]
           maxport = int(t[2]) + 1

           for port in xrange(1, maxport):
               s = socket(AF_INET, SOCK_STREAM)
               try:
                  s.connect((host, port))
                  self.TextBox.insert(Tkinter.END,"Port %d is open" % port)
               except error:
                   continue
    	except IndexError:
         self.TextBox.insert(Tkinter.END,  "Usage: %s <ip address> <max port>" % t[0])
     	except ValueError:
         self.TextBox.insert(Tkinter.END, "Port must be a valid integer")
     	except Exception, e:
         print e

    def Run(self):
        self.root.mainloop()

if (__name__=="__main__"):
    Scanner().Run()

Reply With Quote
  #4  
Old November 30th, 2003, 02:44 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
When i run your script it works fine, at least up untill i enter an IP (my localhost) then it freezes.. so i think we can narror it down too somewhere around your s.connect() line.

Unfortunatly im not really a Tk expert; too be sure i'd try removing the socket and see if it works then, at least then we know where to start!

Mark.

Reply With Quote
  #5  
Old November 30th, 2003, 03:36 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
In port() I guess you need to split the response sting t first and index from 0 not one.

You could consider a regular expression check to confirm the valid format of the user input.

Reply With Quote
  #6  
Old November 30th, 2003, 03:45 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Oh, while i think of it, you should move 's = socket(AF_INET, SOCK_STREAM)' to outside your loop! you def' don't want to create a new socket instance each time!

mark.

Reply With Quote
  #7  
Old November 30th, 2003, 08:57 PM
Gerardoj's Avatar
Gerardoj Gerardoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Somewhere over the Rainbow
Posts: 128 Gerardoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 54 m 28 sec
Reputation Power: 5
I changed it without Tkinter, and now is working fine. How can I add the results into the Textbox in the Tkinter code?

Thanks a lot.


Code:
#!/usr/bin/env python

from socket import *
import sys

try:
    host = sys.argv[1]
    maxport = int(sys.argv[2]) + 1

    for port in xrange(1, maxport):
        s = socket(AF_INET, SOCK_STREAM)
        try:
            s.connect((host, port))
            print "Port %d is open" % port
        except error:
            continue
except IndexError:
    print "Usage: %s <ip address> <max port>" % sys.argv[0]
except ValueError:
    print "Port must be a valid integer"
except Exception, e:
    print e

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Adding code to GUI


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway