[ Curiosity,Experimentation ]

Random stuff from the parallel universe of Ones and Zeroes

Optimized Port Scanner [With Threading]

Posted by appusajeev on August 13, 2009

I had earlier presented here a Port Scanner program written in Python (In fact,it was my maiden post !). I had stated that the major bottleneck associated with its performance was the amount of time taken to complete the scan for even a small range of ports. The connections were made sequentially,one after the other and took mammoth time to verify the entire ports in the list.

Well,that problem is solved now by using threaded execution,the use of separate threads for processing each port. The entire ports are processed simultaneously by separate  threads and this has brought down the execution time to a great extent.Hence i am presenting here, an optimized version of the port scanner which i had earlier presented.

A thread is a sequence  of instructions that are executed concurrently with other instructions/threads. Python provides two modules to implement threading-Thread module and Threading module. I have used the latter module and has overridden the run() method in the Thread class(by subclassing it)present in the module Threading.

Download Source code

Or see the source below:

Port Scanner-Optimized Source

Port Scanner-Optimized Source

Here the scanner in action:

”]Port Scanning [Screenshot]

I have used microsoft.com as the example. Notice from the scan that port 443 is open. Its the port for HTTPS.

Suggestions are welcome

Port Scanner -Scanning

9 Responses to “Optimized Port Scanner [With Threading]”

  1. brj said

    it this similar to the the thread and run in java?

  2. shameer said

    nice one

  3. aodrulez said

    Hi! Well good work there mate.
    Hmm if am not wrong..u are using range()
    function which never uses the actual ending
    “last port” number.as its evident from the output,
    port no. 450 is not tested.

    🙂 using threads is good but i guess.. such
    “sequential”(in the sense.. u r anyways scanning
    port numbers in sequence..rite?)
    scanning on a remote host.. with such a lot of
    simultaneous traffic is goin to make the remote
    hosts’ IPS/IDS/Firewall go paranoid.

    but overall…a kewl attempt…n keep up the
    good work!..
    (i know,i know..u never really cared about that
    IPS/IDS/firewall thingy… 😉 )

    take care.

  4. Sanjay said

    similar to threading in java….but threading is way lot easier in python compared to cpp or something

  5. You shouldn’t put up jpgs of your code. No one can cut/paste them and google cannot crawl them. Put them up using monospaced fonts.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: