Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

Portscanner in python


Portscanner in python

By ghostghost | 6169 Reads |
0     0

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
ghost's avatar
ghost 18 years ago

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..

ghost's avatar
ghost 18 years ago

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.

ghost's avatar
ghost 18 years ago

pretty good, i'd still use nmap though :P.

ghost's avatar
ghost 18 years ago

Yeah i left it scanning over night and it hasn't got to 65535 yet! Lol and thats a localhost scan

ghost's avatar
ghost 18 years ago

:p

ghost's avatar
ghost 17 years ago

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?

ghost's avatar
ghost 17 years ago

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.