[ Curiosity,Experimentation ]

Random stuff from the parallel universe of Ones and Zeroes

Posts Tagged ‘Socket’

An Asynchronous Socket Class in Python

Posted by appusajeev on November 23, 2009

The default socket module can be a pain certain times,especially when you are working with asynchronous/event driven domain.Handling asynchronous communication can be a bit messy in the native python environment .The accept() and recv() methods would only relinquish control after a connection has been accepted or data has arrived. This would sometimes choke the flow of control in the program..
So i thought of creating a socket class utilizing threads internally to handle asynchronous communication and this is what i have finally arrived at.
The Winsock control in VB provides a clean yet powerful interface to handle asynchronous socket communication.I have tried to provide an interface similar to the Winsock control. I have also incorporated callback mechanism by which a function could be invoked upon data arrival.This avoids the need to poll the socket every time. As of now i have just provided the methods working upon TCP,UDP is not yet supported though adding UDP support is trivial ! 🙂

Download Source

An Asynchronous Socket Class in Python Source

An Asynchronous Socket Class in Python

Posted in Asynchronous_Socket, Python | Tagged: , | 3 Comments »

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

Posted in Port Scanner, Python | Tagged: , , | 9 Comments »

A Minimal Cross-platform Port Scanner in Python

Posted by appusajeev on July 6, 2009

A  Port Scanner is one of the most basic tools in the arsenal of an attacker/administrator. Basically a port scanner is a tool which can identify the open ports on a remote system. Given an ip address and an optional port range,a port scanner tries to connect to the ports on the machine sequentially and a successful connection means an open port. Open ports can sometimes prove to be a juicy entry point for an attacker,when there is a vulnerable application/service on the other side with an open port.

With that basic idea,presented here is a minimal port scanner i developed Python.

No rocket science,pretty straight forward code. The source can be altered to make it a portsweeper even

You can download the source here

The source is displayed below. And remember,this is a simple portscanner .So no advanced features

Port Scanner Source

Port Scanner Source

First,the program checks for the right number of command line arguments which includes the remote IP address,starting port and ending port. After extracting these parameters , a TCP socket is created each time to connect to the different ports sequentially on the same machine. A successful connection means that that port is open and some application/service is listening to it.

Currently what bothers me is the time taken to complete the scan. It takes quite some time :d

Suggestions and bug reports are welcome…….

Posted in Port Scanner, Python | Tagged: , | 4 Comments »