Follow us on Twitter!
You cannot teach a man anything; you can only help him find it within himself. - Galileo
Friday, April 25, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 23
Guests Online: 23
Members Online: 0

Registered Members: 82909
Newest Member: awais
Latest Articles

portscanner in python

Arrow Image simple portscanner in python



How to make a simple port scanner in python:

okay first we need to understand what a portscanner does, basically it is a programming which normally by trial and error checks which ports are open on a said computer.

To make a portscanner we need to understand what our program must do. Well basically it should request an IP to scan and the ports to scan( this while be quite slow at scanning so it is preferable if it was as selective as needed) then it must attempt to cnnect in turn to these ports and some how out put the status.( I use a log file as it is more usfull than an OSD and it would be too slow to use both.

okay so what we need to learn about is how to: -capture keybord input.
-probably how to make a while clause
-connect to a port

easy enough.so please learn about sockets, raw_input while and basically the basics of python before trying my code :D well heres my code:

#!/python24 #location of my python install
import socket #we need to import the socket function to connect
host = raw_input(\"What is the IP? \") # gather needed info
port0 = raw_input(\"What is the starting port? \")
port1 = raw_input(\"What is the finishing port? \")
output = raw_input(\"What shall the log output file be called? \")
port = port0 # make sure it starts at start port
print \"Scanning ports...\"#astetics are always nice and if your program malfuctuins its easier to locate
z = open(output + \".txt\", \"a\")#opening the file we need we do this once and before thewhile so its faster
z.write(\"Scan result: \")
while int(port) <= int(port1):# tell it when to stop. and use the interger bit int() because else it wont use numbers
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)#open the socket and connect
s.connect((host, int(port)))
z.write(\"Port: \" + str(port) + \" is open. \")#if it connects it\'s open ;)
s.close()
print port
port = int(port) + 1 #move on to next port :D
except socket.error:# if the socket doesnt work then it\'s closed ;)
z.write(\"Port: \" + str(port) + \" is closed. \")
s.close()
print port
port = int(port) + 1
#nothng so the program will exit

#the author me,(wolfmankurd) didnt make you do anything so no law suits please :D ToS style use at your own risk.

Comments

thousandtooneon July 30 2005 - 18:51:01
Well, it's not bad. The only problem is, posting you're code and writing like 3 line about it isn't really an article. All I'd suggest is further explain you're code. It's fairly obvious if you've programmed before, but for anyone just starting..
wolfmankurdon August 03 2005 - 17:00:34
well I made this program the same evening as learning python, its my first time programming so it cant be that complexe.. It's very simple had the reader looked up a single tutorial and read up on the topics i suggested... Howevever i can not help the reader actully be able to have ideas how to do things. That seems to be the main parrt of programming.
scankyfrankon August 03 2005 - 17:20:54
pretty good, i'd still use nmap though Pfft.
wolfmankurdon August 05 2005 - 11:40:54
Yeah i left it scanning over night and it hasn't got to 65535 yet! Lol and thats a localhost scan
WaTcHeRon September 11 2005 - 17:40:17
Pfft
FuKeon August 04 2006 - 10:16:29
I have a questing.. Is port scanning illegal? And if it is, is the chance to get caught big? Even if i sit behind a proxy?
Greekilon October 02 2006 - 03:20:19
I'm new to python, so sorry if this is just stupid, but why do you convert port to an integer every time you use it? Other than that, everything looks fine (although maybe abit unclear). You get a very good from me.
Post Comment

Sorry.

You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.