#######################################################
#                                                     #
#       _____     _____//  ___     _____              #
#      |  ___|   / ____ \  | |    |  _  \             #
#      |  |      | |//| |  | |    | | |  |            #
#      |  |___   | |//| |  | |___ | |_|  |  ____      #
#      |______|  \______/  |____| |_____/  |____|     #
#                //                                   #
#                                                     #
#          ::c0ldphuz10n.googlepages.com::            #
#                                                     #
# A simple portscanner in python. When prompted to,   #
# enter the IP, the maximum por to scan to (starting  #
# from 1). If you do not want it to output to a file  #
# type null when prompted for a filename.             #
#                                                     #
# As usual with this kind of thing, don't do anything #
# stupid, some admins get their knickers in a knot    #
# over portscanning, so be careful.                   #
#######################################################

#!/usr/bin/env python
import sys, time, socket, os.path

# scan: the method that attemps connections to ports on host
def scan(host,port):
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		sock.connect((host, port))
		return 1
	except socket.error, reason:
		return 0
		
def main():
	print ""
	print "::c0ldphuz10n.googlepages.com::"	
	print "Simplescan.py: a basic portscanner by c0ld_phuz10n"
	
	# get info from the user for the scan as well as output
	hostname =  raw_input ("Target IP: ")
	portrange =  range(input ("Port range: "))
	filename =  raw_input ("Enter a file name: ")
	openports = []
	
	print "Scaning ports..."
	for port in portrange:
		if scan(hostname, port):
			openports.append(port)
	print openports	
	
	if filename != "null":
		FILE = open(filename, "w")	# open our file in writemode
		FILE.writelines("::c0ldphuz10n.googlepages.com::\n")
		FILE.writelines(hostname + " in the range: 1-" + str(len(portrange)) + "\n")
		FILE.writelines(str(time.ctime()) + "\n")
		FILE.writelines("Portscan results:\n\n")
		for x in range (0, len(openports)):
			FILE.writelines(str(openports[x]) + "\n")	
		FILE.close
		print "Results written to " + filename

	print ""

main()

