473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

threading a thread

I have a program written in Python that checks a class B network (65536
hosts) for web servers. It does a simple TCP socket connect to port 80
and times out after a certain periods of time. The program is threaded
and can do all of the hosts in about 15 minutes or so. I'd like to make
it so that I can check for other open ports (instead of just port 80)
and I'd like to thread the port checks as well.

Right now I'm just prototyping and the threaded hosts portion works very
well for my needs. I'd just like to add a threaded ports check and
wanted to know if anyone had done something similar in Python.

Many thanks
Feb 27 '07 #1
6 2166
tubby wrote:
Right now I'm just prototyping and the threaded hosts portion
works very well for my needs. I'd just like to add a threaded
ports check and wanted to know if anyone had done something
similar in Python.
Taken the vast amount of threads you'll need, there will be a big
overhead. Using a different means of concurrency is advisable.

BTW, why not use nmap?

Regards,
Björn

--
BOFH excuse #394:

Jupiter is aligned with Mars.

Feb 27 '07 #2
Bjoern Schliessmann wrote:
tubby wrote:
>Right now I'm just prototyping and the threaded hosts portion
works very well for my needs. I'd just like to add a threaded
ports check and wanted to know if anyone had done something
similar in Python.

Taken the vast amount of threads you'll need, there will be a big
overhead. Using a different means of concurrency is advisable.

BTW, why not use nmap?
Have you tried it? Nmap is sequential. It takes about 5 hours to do web
server checks (port 80 only) on a class B network... I think it does
ports in parallel, but not hosts. Even when you use the insane time
setting the wait is untimely.

I can do the same thing in roughly 15 minutes with Python or Ruby using
threads. Granted, Nmap is much more configurable and flexible, but it
simply does not scale to address large networks...nessus is the same way.

Also remember that we're dealing with IPv4 networks now. How will we
deal with larger IPv6 address spaces. Besides clustering and distributed
processing (mapreduce), it seems that threads may help deal with some of
the scaling issues I face right now.
Feb 27 '07 #3
tubby wrote:
Have you tried it? Nmap is sequential.
RTFM?

| NMAP(1) Nmap Reference Guide NMAP(1)
| [...]
| TIMING AND PERFORMANCE
| [...] While Nmap utilizes parallelism and many advanced
| algorithms to accelerate these scans, the user has ultimate
| control over how Nmap runs.
|
| --min-hostgroup <numhosts>; --max-hostgroup <numhosts>
| (Adjust parallel scan group sizes)
| [...]
| --min-parallelism <numprobes>; --max-parallelism <numprobes>
| (Adjust probe parallelization)
| [...]
I can do the same thing in roughly 15 minutes with Python or Ruby
using threads.
Have fun.
Also remember that we're dealing with IPv4 networks now. How will
we deal with larger IPv6 address spaces. Besides clustering and
distributed processing (mapreduce), it seems that threads may help
deal with some of the scaling issues I face right now.
Please observe that there are simpler and easier (in many cases)
means of parallelisation. For example Unix' select().

Regards,
Björn

--
BOFH excuse #368:

Failure to adjust for daylight savings time.

Feb 28 '07 #4
Bjoern Schliessmann wrote:
tubby wrote:
>Have you tried it? Nmap is sequential.

RTFM?
I urge you to actually try it and see for yourself. From my experience,
it sucks... even when only doing 1 port it takes hours regarless of what
the man page implies.

I'll figure it out, thanks, Tubby.
Feb 28 '07 #5
Bjoern Schliessmann wrote:
RTFM?
One last things... here's a *very* small sample netstat output from a
threaded py script:
tcp 0 1 192.168.1.100:41066 192.168.17.132:www SYN_SENT
tcp 0 1 192.168.1.100:46412 192.168.5.132:www SYN_SENT
tcp 0 1 192.168.1.100:58297 192.168.83.132:www SYN_SENT
tcp 0 1 192.168.1.100:44011 192.168.157.4:www SYN_SENT
tcp 0 1 192.168.1.100:51936 192.168.243.4:www SYN_SENT
tcp 0 1 192.168.1.100:40812 192.168.39.132:www SYN_SENT
tcp 0 1 192.168.1.100:41903 192.168.155.4:www SYN_SENT
tcp 0 1 192.168.1.100:39110 192.168.35.132:www SYN_SENT
tcp 0 1 192.168.1.100:33060 192.168.59.132:www SYN_SENT
tcp 0 1 192.168.1.100:33060 192.168.59.132:www SYN_SENT
tcp 0 1 192.168.1.100:46544 192.168.15.132:www SYN_SENT
tcp 0 1 192.168.1.100:51863 192.168.119.132:www SYN_SENT
tcp 0 1 192.168.1.100:51666 192.168.117.132:www SYN_SENT
tcp 0 1 192.168.1.100:60085 192.168.85.132:www SYN_SENT
tcp 0 1 192.168.1.100:57431 192.168.195.4:www SYN_SENT
tcp 0 1 192.168.1.100:48253 192.168.31.132:www SYN_SENT
tcp 0 1 192.168.1.100:48253 192.168.31.132:www SYN_SENT
tcp 0 1 192.168.1.100:55402 192.168.251.4:www SYN_SENT
tcp 0 1 192.168.1.100:48510 192.168.159.4:www SYN_SENT
tcp 0 1 192.168.1.100:46516 192.168.23.132:www SYN_SENT
tcp 0 1 192.168.1.100:60412 192.168.73.132:www SYN_SENT
tcp 0 1 192.168.1.100:56050 192.168.127.132:www SYN_SENT
tcp 0 1 192.168.1.100:58080 192.168.199.4:www SYN_SENT
tcp 0 1 192.168.1.100:58080 192.168.199.4:www SYN_SENT
tcp 0 1 192.168.1.100:55805 192.168.253.4:www SYN_SENT
tcp 0 1 192.168.1.100:57871 192.168.69.132:www SYN_SENT
tcp 0 1 192.168.1.100:50699 192.168.225.4:www SYN_SENT
tcp 0 1 192.168.1.100:50245 192.168.227.4:www SYN_SENT
tcp 0 1 192.168.1.100:34634 192.168.161.4:www SYN_SENT
tcp 0 1 192.168.1.100:43256 192.168.97.132:www SYN_SENT
tcp 0 1 192.168.1.100:58740 192.168.173.4:www SYN_SENT
tcp 0 1 192.168.1.100:40337 192.168.211.4:www SYN_SENT
tcp 0 1 192.168.1.100:46584 192.168.15.4:www SYN_SENT
tcp 0 1 192.168.1.100:37866 192.168.175.132:www SYN_SENT
Now, try doing a netstat while you're running a 'parallel' nmap report
and see the difference for yourself. It's huge. Have you ever actually
tried what you recommended???
Feb 28 '07 #6
tubby wrote:
I have a program written in Python that checks a class B network (65536
hosts) for web servers. It does a simple TCP socket connect to port 80
and times out after a certain periods of time. The program is threaded
and can do all of the hosts in about 15 minutes or so. I'd like to make
it so that I can check for other open ports (instead of just port 80)
and I'd like to thread the port checks as well.
So far, I understand that you have a program with multithreading, but it
only threads the host checking (because it actually scans one port
only).

Right now I'm just prototyping and the threaded hosts portion works very
well for my needs. I'd just like to add a threaded ports check and
wanted to know if anyone had done something similar in Python.
What I do *not* understand if this is a question about:

- port checking (asume not, because the program already checks a port,
so you can actually see how it's done)

- threading (asume not, because the program already is multithreading,
so you can actually see how it's done)

- modifying your program (asume not, you did not copy it here).
So, for us be able to help you, what can not you do?

Regards,

--
.. Facundo
..
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/

Mar 5 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
2
by: CK | last post by:
I am a "newbie" to python and today I had the need to write a program which generated a lot of tcp connections to a range of addresses (10.34.32.0/22) in order to troubleshoot a problem with a...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
13
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
13
by: John | last post by:
I've got some reasonably complex business logic in my C# code, in a class called by a ASP.NET page. This takes around 3-4 seconds to execute. It's not dependent on SQL calls or anything like that....
2
by: Vjay77 | last post by:
In this code: Private Sub downloadBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not (Me.downloadUrlTextBox.Text = "") Then Me.outputGroupBox.Enabled = True...
17
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. ...
4
by: DBC User | last post by:
I have a background process which reads a table to see if there are any pending requests. If there are any, then it will start a worker thread (only 10 allowed at a time) and executes a method. In...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.