Advertisement

04.11.2008 at 07:34AM PDT, ID: 23315202
[x]
Attachment Details

Python asyncore.dispatcher test not functioning as intended?

Asked by dr34m3rs in Python Scripting Language

Tags:

Hi Python Experts,

It is my understanding that the asyncore module is intended to provide an alternative to threading? Am I mistaken to think that my code should work in parallel and not sequential?

The test code is a simple IP scanner that will test one port in a given IP range. If I use threading I can get 40 scanners active at one time that don't block each other, however if I go with the asyncore style (which uses select() ), it becomes sequential... if you try this yourself, make sure you use a not so common port (8080 on a hosting IP range gives a good example of the behavior). Could it be something else on my system (Linux fedora 8)?

Thank you very much for any help.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
#!/usr/bin/python
 
import asyncore, socket
 
host = "(first 3 octets of an ip address)"
port = # a port goes here
 
class http_client(asyncore.dispatcher):
	def __init__(self, host, port):
		asyncore.dispatcher.__init__(self)
		self.host = host
		self.port = port
		self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
		self.setblocking(0)
		self.settimeout(3)
		print "Connecting to "+str(self.host)+" on port "+str(self.port)
		try:
			self.connect((self.host, self.port))
		except:
			self.close()
	def handle_connect(self):
		print str(self.host)+" on port "+str(self.port)+" OPEN"
		self.close()
	def handle_close(self):
		self.close()
	def handle_read(self):
		self.close()
	def writable(self):
		self.close()
	def handle_write(self):
		self.close()
 
digit = 1
while digit < 255:
	zhost = str(host)+'.'+str(digit)
	c = http_client(zhost, port)
	try:
		asyncore.loop()
	except: pass
	digit += 1
 
 
[+][-]04.11.2008 at 08:44AM PDT, ID: 21335331

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 09:45AM PDT, ID: 21335879

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 10:50AM PDT, ID: 21336519

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 10:51AM PDT, ID: 21336527

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 10:52AM PDT, ID: 21336545

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 02:41PM PDT, ID: 21338427

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 02:59PM PDT, ID: 21338552

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 03:45PM PDT, ID: 21338787

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 03:55PM PDT, ID: 21338828

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 04:29PM PDT, ID: 21338953

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.14.2008 at 03:09AM PDT, ID: 21348769

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Python Scripting Language
Tags: Python
Sign Up Now!
Solution Provided By: RichieHindle
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.14.2008 at 05:44AM PDT, ID: 21349483

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628