PDA

View Full Version : Basic CLI IP + Port scanner



manzalawi
01-29-2011, 11:10 AM
import os
import socket
def ports(host, port):
x = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
try:
x.connect((host, port))
return 1
x.close()
except:
return 0
x.close()
xyz = 1
print """----------------------
IPScannermabob
Usage:
Scan For an IP:
Just Enter the IP and Press Enter

Portscan:
Type portscan

For Help:
Type in help

For credits:
Type credits

To exit:
Type exit
----------------------
--cp
"""
while xyz==1:
ip = raw_input(">> ")
zx = open("log.txt", "a")
if ip.lower()=="exit":
ask = raw_input("Are you sure you want to exit? (Y\\N) ")
if ask.lower()=="y":
exit()
elif ask.lower()=="n":
print("That's what I thought.")
else:
print("Wrong choice. Retard.")
elif ip.lower()=="range":
sec = raw_input("Enter the first 3 sections: ")
b = int(raw_input("Enter beginning number: "))
e = int(raw_input("Enter ending number: "))
while b<=e:
z = os.system("ping "+str(sec)+"."+str(b)+" -n 1")
if z==0:
print(""+str(sec)+"."+str(b)+" is online.")
zx.write(""+str(sec)+"."+str(b)+" is online.\n")

elif z==1:
print("Either "+str(sec)+"."+str(b)+" is offline, or ping request has been blocked.")
zx.write("Either "+str(sec)+"."+str(b)+" is offline, or ping request has been blocked.\n")
b = b + 1
elif ip.lower()=="credits":
print """v1.0 Made by cruddpuppet in python.\nThanks for using!\n\nUPDATES:\nLogging feature added.\nPortScanning added.\nCommon Ports Checking Added.\n"""
elif ip.lower()=="help":
print """Usage:
For a normal IP, just type it in.

For a range of IP's, type in range, then enter in the first 3 sections (EX:127.0.0), then the starting point (EX:1) and then the ending point (EX:10)

For portscanning, type in portscan and enter the host, and then the port to scan. """
elif ip.lower()=="portscan":
ps = raw_input("Scan what? ")
if ps.lower()=="range":
host = raw_input("Enter host: ")
pb = int(raw_input("Enter starting port: "))
pe = int(raw_input("Enter ending port: "))
while pb<=pe:
if ports(host, pb):
print("Port "+str(pb)+" is open on "+host+".")
zx.write("Port "+str(pb)+" is open on "+host+".\n")
else:
print("Port "+str(pb)+" is closed on "+host+".")
zx.write("Port "+str(pb)+" is closed on "+host+".\n")
pb= pb + 1
elif ps.lower()=="common":
commonscan = raw_input("Host: ")
if ports(commonscan, 21):
print("Port 21 (FTP) is open on "+commonscan+".")
zx.write("Port 21 (FTP) is open on "+commonscan+".\n")
else:
print("Port 21 (FTP) is closed on "+commonscan+".")
zx.write("Port 21 (FTP) is open on "+commonscan+".\n")
if ports(commonscan, 22):
print("Port 22 (SSH) is open on "+commonscan+".")
zx.write("Port 22 (SSH) is open on "+commonscan+".\n")
else:

print("Port 22 (SSH) is closed on "+commonscan+".")
zx.write("Port 22 (SSH) is closed on "+commonscan+".\n")
if ports(commonscan, 23):
print("Port 23 (Telnet) is open on "+commonscan+".")
zx.write("Port 23 (Telnet) is open on "+commonscan+".\n")
else:

print("Port 23 (Telnet) is closed on "+commonscan+".")
zx.write("Port 23 (Telnet) is closed on "+commonscan+".\n")
if ports(commonscan, 25):
print("Port 25 (SMTP) is open on "+commonscan+".")
zx.write("Port 25 (SMTP) is open on "+commonscan+".\n")
else:

print("Port 25 (SMTP) is closed on "+commonscan+".")
zx.write("Port 25 (SMTP) is closed on "+commonscan+".\n")
if ports(commonscan, 79):
print("Port 79 (Finger) is open on "+commonscan+".")
zx.write("Port 79 (Finger) is open on "+commonscan+".\n")
else:

print("Port 79 (Finger) is closed on "+commonscan+".")
zx.write("Port 79 (Finger) is closed on "+commonscan+".\n")
if ports(commonscan, 80):
print("Port 80 (HTTP) is open on "+commonscan+".")
zx.write("Port 80 (HTTP) is open on "+commonscan+".\n")
else:

print("Port 80 (HTTP) is closed on "+commonscan+".")
zx.write("Port 80 (HTTP) is closed on "+commonscan+".\n")
if ports(commonscan, 110):
print("Port 110 (POP3) is open on "+commonscan+".")
zx.write("Port 110 (POP3) is open on "+commonscan+".\n")
else:

print("Port 110 (POP3) is closed on "+commonscan+".")
zx.write("Port 110 (POP3) is closed on "+commonscan+".\n")
if ports(commonscan, 143):
print("Port 143 (IMAP) is open on "+commonscan+".")
zx.write("Port 143 (IMAP) is open on "+commonscan+".\n")
else:

print("Port 143 (IMAP) is closed on "+commonscan+".")
zx.write("Port 143 (IMAP) is closed on "+commonscan+".\n")
if ports(commonscan, 1083):
print("Port 1083 (SOCKS) is open on "+commonscan+".")
zx.write("Port 1083 (SOCKS) is open on "+commonscan+".\n")
else:

print("Port 1083 (SOCKS) is closed on "+commonscan+".")
zx.write("Port 1083 (SOCKS) is closed on "+commonscan+".\n")
if ports(commonscan, 5190):
print("Port 5190 (AIM) is open on "+commonscan+".")
zx.write("Port 5190 (AIM) is open on "+commonscan+".\n")
else:

print("Port 5190 (AIM) is closed on "+commonscan+".")
zx.write("Port 5190 (AIM) is closed on "+commonscan+".\n")
if ports(commonscan, 5010):
print("Port 5010 (Yahoo) is open on "+commonscan+".")
zx.write("Port 5010 (Yahoo) is open on "+commonscan+".\n")
else:

print("Port 5010 (Yahoo) is closed on "+commonscan+".")
zx.write("Port 5010 (Yahoo) is closed on "+commonscan+".\n")
if ports(commonscan, 4000):
print("Port 4000 (ICQ) is open on "+commonscan+".")
zx.write("Port 4000 (ICQ) is open on "+commonscan+".\n")
else:

print("Port 4000 (ICQ) is closed on "+commonscan+".")
zx.write("Port 4000 (ICQ) is closed on "+commonscan+".\n")
else:
host = raw_input("Enter host: ")
xport = int(raw_input("Enter the port: "))
if ports(host, xport):
print("Port "+str(xport)+" is open on "+host+".")
zx.write("Port "+str(xport)+" is open on "+host+".\n")
else:
print("Port "+str(xport)+" is closed on "+host+".")
zx.write("Port "+str(xport)+" is closed on "+host+".\n")
else:
x = os.system("ping %s -n 1" %ip)
if x==0:
print("%s is online." %ip)
zx.write("%s is online.\n" %ip)
elif x==1:
print("Either %s is offline, or ping request has been blocked." %ip)
zx.write("Either %s is offline, or ping request has been blocked.\n" %ip)


dont 4get say thx :)

pascalll2222
02-01-2011, 08:19 AM
thank you mannn

qwerty
02-05-2011, 09:10 PM
thnxxxx u, bro

ojitosfachas
02-05-2011, 09:43 PM
thxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

zaki1971
02-27-2011, 10:49 AM
Nice post man!

kebo_angel
03-01-2011, 06:41 PM
thanks bro nice thread bro

cado
03-10-2011, 11:30 PM
i don't understand but i say thx loolz

sdzwb
03-12-2011, 03:32 AM
nice script
thanks for sharing

adydryx
03-13-2011, 12:09 AM
Nice Code.. Thanks Man!

otheridentity
03-17-2011, 12:58 AM
it doesnt seem to make sense to me

xtrcom
03-19-2011, 12:28 AM
cheers mancheers mancheers mancheers man

ndd
03-19-2011, 05:54 AM
thxxx bro....

ndd
03-19-2011, 05:55 AM
thnx bro again

mc0d3
03-19-2011, 04:53 PM
nicee and juicy thank you dude