Python Port Scanner

April 4, 2018 | Views: 3208

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

The following python code will allow you to scan a local or remote host for open ports. The program scans for select ports on a certain IP address and reflects the open ports back to the user.

 

#import socket library

from socket import *

 

#User prompts for IP and Ports

print “This tool should be used to verify open ports on the machine n”

print “Please follow the steps provided to check ports. n”

ip=raw_input(“Enter the IP of the machine that you would like to scan: “) #prompts user to enter in the pema ip

print “n”

print “-” * 60

print “Please enter the range of ports you would like to scan on the machine”

print “-” * 60

sport=input(“Enter first port number to scan: “)

print “n”

endport=input(“Enter last port number to scan:”)

print “n”

 

# Banner

print “-” * 60

print “Please wait, scanning remote host”, ip

print “-” * 60

print “All connected ports between “, sport, ” and “, endport, ” will display”

print “-” * 60

print “Press Ctrl + C to stop scan”

print “-” * 60

 

#Informs user of successful connections

for port in range(sport,endport,):

s=socket(AF_INET, SOCK_STREAM)

if(s.connect_ex((ip, port))==0):

print “Port” , port, “is open on PEMA ” + pema_ip

s.close()

 

Thanks for looking!

Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Ready to share your knowledge and expertise?
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel