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:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 18th, 2003, 05:08 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
Trouble with int values

Hi. I have a problem in my script.

the problem is that when I type some IP in the Text2, just read one number.

example:

When I type :
127.0.0.1 80, just read the 7

I would like that read the last 2 (80) number. what could be the problem?

Thanks

Code:
	b = BannerGrabber.BannerGrabber(self.components.Text2.text[1])
	
	for i in self.components.Text2.text[2:]:
    	    if b.connect(int(i)):
                try:
                    self.components.Text1.text = "Port %s: %s" % (i,b.getBanner())
                    b.close()
                except Exception,e:
                    print e
            else:
        	
		self.components.Text1.text =  mess + "Port %s: (closed)" % i

Reply With Quote
  #2  
Old December 18th, 2003, 05:32 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
Ok you lost me again, could you attach your whole program, it would make it easier since what you posted doesn't show much at all

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


Last edited by netytan : December 18th, 2003 at 05:36 PM.

Reply With Quote
  #3  
Old December 18th, 2003, 06:10 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. Attached the whole code.
Attached Files
File Type: gz scan.tar.gz (1.3 KB, 205 views)

Reply With Quote
  #4  
Old December 18th, 2003, 07:02 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
Ah ok this is kinda crazy , and i dont have pyCard which makes this very hard.

In any case your variable self.components.Text2.text[1] isnt defined as far as i can see in your code, also using a slice like that on a string (which i guess text is) you get a single letter

On the plus side i cant see anything wrong with your BannerGrabber() class. So we can narrow this down to your Scan file. I cant also see Scan.rscr.py beign used anywhere, so is this being used by something in pyCard?

Mark.

Reply With Quote
  #5  
Old December 18th, 2003, 07:47 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
Yeah Scan.rscr.py is used with PythonCard to setup your textboxes or checkboxes and all kind of objects. I changed for Tkinter maybe you can help with the new attached file.
Attached Files
File Type: gz scan.tar.gz (1.3 KB, 273 views)

Last edited by Gerardoj : December 18th, 2003 at 07:57 PM.

Reply With Quote
  #6  
Old December 23rd, 2003, 12:50 PM
theperfectsoup theperfectsoup is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 35 theperfectsoup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Re: Trouble with int values

Quote:
Originally posted by Gerardoj

Code:
	b = BannerGrabber.BannerGrabber(self.components.Text2.text[1])
	
	for i in self.components.Text2.text[2:]:
    	    if b.connect(int(i)):
                try:
                    self.components.Text1.text = "Port %s: %s" % (i,b.getBanner())
                    b.close()
                except Exception,e:
                    print e
            else:
        	
		self.components.Text1.text =  mess + "Port %s: (closed)" % i


Most likely the problem is Text2.text is a string; you're trying to access the port number, I assume, by trying to access it as the second element of some array (the IP address being the first). But a string is not the same as an array -- to break up the string into an array, you can use split:

Code:
>>> addr = "127.50.80.90 54"
>>> addr
'127.50.80.90 54'
>>> ip, port = addr.split(' ')
>>> ip
'127.50.80.90'
>>> port
'54'


If you don't need the IP address, and just the port, you can do it all in one line:

Code:
>>> addr.split(' ')[1]
'54'


So I think you'd want:

Code:
	for i in self.components.Text2.text.split(' ')[1]:


Since that's only going to iterate over one element, that single port, you might want to remove the for loop altogether.

Cheers,

- tps

Last edited by theperfectsoup : December 23rd, 2003 at 12:56 PM.

Reply With Quote
  #7  
Old December 23rd, 2003, 03:12 PM
ragabash ragabash is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Yuma,AZ
Posts: 11 ragabash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to ragabash Send a message via Yahoo to ragabash
Just some quick pseudo-code.


I think your looking for something being processed a bit more in your for loop before you get to your slice. I'm guessing that your grabbing a bunch of results from a scan and processing those (if not see soups idea). Something more like this:

#massage the results from the scan into
#a nice array first

for i in scan_rslts_array:
if b.connect(int(i[-2:]): #count two back from end of slice for port
try:
self.components.Text1.text = "Port %s: %s" % (i[-2:]b.getBanner())
b.close()
except Exception.e:
print e
else:
self.components.Text1.text = mess + "Port %s: (closed)" % i[-2:]

Ugly with the slices. Prolly should put a my_slice = i[-2:] near the top to clean it up a little.

-rag

Reply With Quote
  #8  
Old December 24th, 2003, 12:22 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
Thanks all for your help. Still have a problem, I changed my code and for i in self.components.Text2.text.split(' ')[2]:
IndexError: list index out of range
shows up. When I change for self.components.Text2.text.split(' ')[1]:. runs fine, but just read the last integer What could be the problem?.

Code:
	b = BannerGrabber.BannerGrabber(self.components.Text2.text[1])
	
	for i in self.components.Text2.text.split(' ')[2]:

    	    if b.connect(int(i[-2:])):
                try:
                    self.components.Text1.text = "Port %s: %s" % (i,b.getBanner())
                    b.close()
                except Exception,e:
                    print e
            else:
        	
		self.components.Text1.text =  mess + "Port %s: (closed)" % i 

Reply With Quote
  #9  
Old December 24th, 2003, 06:50 AM
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
Have you tried

print self.components.Text2.text.split(' ')
print self.components.Text2.text.split(' ')[2]
to see what you get?

Grim

Happy bug hunting holidays

Reply With Quote
  #10  
Old December 24th, 2003, 07:40 AM
ragabash ragabash is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Yuma,AZ
Posts: 11 ragabash User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to ragabash Send a message via Yahoo to ragabash
(Lengthy post. Sorry)

Your index in your array is off. Array indexes (indices? Too early...) start at 0. So if you fire up IDLE:
Code:
ip_port = '172.0.0.1 80'
ip_array = ip_port.split(' ') # Array is now '172.0.0.1' and '80'
print ip_array[0] #Should print '172.0.0.1'
print ip_array[1] #Prints '80'


Now before I go on, what exactly are you trying to accomplish in your for loop? It seems like your not working with an array of IP and port numbers, instead just working on one single one.


Code:
#for loop unrolled a little for clarity
Text2_array = self.components.Text2.text.value.split(' ')
#Text2_array[0] is now '172.0.0.1'
#Text2_array[1] is now '80'
#Text2_array[2] is nothing and will throw an out of bounds exception

for i in Text2_array[1] #This loops through the values in ONLY element [1]
#IE the first time through i= '8', the second i= '0' and then falls through.

#rest of loop


OK, assuming that Text2.text is going to be equal to something like:

172.0.0.1 80
172.0.0.2 80
172.0.0.3 80

Then this code will work:

Code:
for i in self.components.Text2.text.split('\n'):
    ip, port = i.split(' ')
    b = BannerGrabber.BannerGrabber(ip)
     if b.connect(int(port)):
        try:
            self.components.Text1.text = "Port %s: %s" % (port,,b.getBanner())
             b.close()
          else:
               self.components.Text1.text = mess + "Port %s: (closed)" % port


BTW try to give your variables names other then their default. I know on small projects like this it doesn't matter much, but on big ones you'll save DAYS.

-rag

Reply With Quote
  #11  
Old December 24th, 2003, 06:04 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
Hey Thanks a lot. Now is working fine, and thanks for the suggestion about variables.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Trouble with int values


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 |