Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Developing a Port Scanner in Python

  1. #11
    Senior Member
    Join Date
    May 2003
    Posts
    472
    HTRegz: really awesome.

    "I've got one question: is it possible to make executables with Python so they can be run on another computer that doesn't have the interpreter installed?"
    mjk : yes, you can do that.
    One of the links pointed out earlier is py2exe.
    Same exists for linux also, it is called freeze and comes with standard installtion. This link should be helpful http://wiki.python.org/moin/Freeze
    Also IronPython is another python implementation for .Net platform by Microsoft which allows you to make .net binaries.
    So be it exe, elf or .Net binary, you can do it.
    guru@linux:~> who I grep -i blonde I talk; cd ~; wine; talk; touch; unzip; touch; strip; gasp; finger; mount; fsck; more; yes; gasp; umount; make clean; sleep;

  2. #12
    Well you don't need a binary for python when using linux. Every linux distro includes python, even slackware. To ensure compatibility, you need to use whats called a shabang as the first line: #! /usr/bin/env or wherever the interpreter is stored. IIRC, debian uses python as part of its installation, or was that a different distro? hmmm.. anyways, htregz, i'm working on a fast tcpscan and fast udpscan using threading. I'd be careful about using the thread module as its been found to cause deadlocks and races within the interpreter itself, which means nothing you do in your program will prevent the thread issues. You should soon switch to threading. I could do the code fix for you.

  3. #13
    heres the fast udp scan version, using threads and and locks to scan multiple ports simultaneously.
    btw, i was wrong about the thread module being dangerous. That was the old version. how embarassed am i? anyways, heres teh fix:
    Code:
    def fastudpscan():
    	"""
    	Threaded udp scan. uses a lock and a central list to indicate which ports are open. 
            The closed list is to ensure that all threads have finished. NOTE: Function coded by Tyler
            Laing on Jan 28/06
    	"""
    	global lock 
    	lock = thread.allocate_lock()
    	global openPorts
    	openPorts = []
    	closedPorts = []
    	for portcounter in range(numberofports):
    		port = int(portstoscan[portcounter])
    		thread.start_new_thread(threadedUdpScan, (timeout, ipaddress, port))
    	while len(openPorts)+len(closedPorts) != numberofports:#this is here to ensure that all threads started have finished
    		pass
    	if len(openPorts) == numberofports:
    		print
    		print "There is a firewall present that is blocking udpscans."
    	else:
    		for port in openPorts:
    			print "Port", port, "is open."
    		
    		
    def threadedUdpScan(timeout, ipaddress, port):
    	"""This takes care of all of the fun scanning part. Ensure that lock is a global lock!"""
            scansocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    	scansocket.settimeout(timeout)
    	try:
    		scansocket.connect((ipaddress, port))
    		scansocket.recv(10)
    		lock.acquire()
    		closedPorts.append(port)
    		lock.release()
    	except socket.timeout:
    		lock.acquire()
    		print ".",#this is here to indicate number of successes.
    		openPorts.append(port)
    		lock.release()
    	thread.exit()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •