I was cheap and I skimmed through "programming python" then jumped off a cliff and went right into it with a ripped parachute. I did a tutorial today and I solved the problem. I'm having a problem with threads and sockets now ... I wrote a lot of code for this and it should work based on my understanding of threads and threading in python. For some reason, the following code does not scan a block of IP's like I had thought that it should. also, no more basic questions, i promise :P
 
Any ideas? (where local host equals your ip or whomever ...)
 
 

class scanThread(threading.Thread):
    def run(self):
        try:
            ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            ss.connect((ip, port_counter))
            print "%s | %d OPEN" % (ip, port_counter)
            ss.close()
        except: pass
# end class -------------------


def scan(ip, begin, end):
 for port_counter in range(begin, end):
            while threading < MAX_THREADS:
                scanThread().start()
# end function -------------------


scan("localhost", 0, 10000)



 
On 9/18/05, Danny Yoo <[EMAIL PROTECTED]> wrote:


Hi Ed,


Let's look at one of your questions:

> How do I use a loops to iterate through the nested tuple

Let's separate this apart from the SQL stuff for the moment.  Are you
familiar with Python's for loop, and how it can work on sequences?  For
example:

######
>>> authors = ['fowler', 'lau', 'gamma', 'helm', 'johnson', 'vlissides']
>>> for a in authors:
...     print "hello", a
...
hello fowler
hello lau
hello gamma
hello helm
hello johnson
hello vlissides
######


Looping across a sequence works regardless of what the elements are, so
that means we can also do this iteration if the elements themselves are
lists:

######
>>> random_numbers = [[3, 1, 4], [1, 5, 9], [2, 6]]
>>> for row in random_numbers:
...     print row
...
[3, 1, 4]
[1, 5, 9]
[2, 6]
######


Does this help answer your question?


I'm getting a feeling that some of the questions you have actually don't
have anything to do with MySQLdb really; instead, it feels like your
questions are really about basic concepts.

Have you already gone through a tutorial like the ones linked from the
Beginner's Guide here?

   http://wiki.python.org/moin/BeginnersGuide

If not, you may want to go through one of them: it'll should help you in
the long run.  Feel free to ask questions here.


Good luck to you!




--
edward hotchkiss
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to