Fetch Open ports using Python Script

  • Post author:
  • Post comments:0 Comments
  • Reading time:18 mins read

Unlock the power of network exploration with Python as we delve into the world of open ports. In this project, you’ll learn how to create a Python script to scan and identify open ports on a target host or network. Understanding open ports is crucial for network security, system administration, and more. This guide is suitable for both newcomers and experienced Python developers. Join us as we embark on a journey to discover open doors in the digital landscape through Python scripting


from socket import *
import time
startTime = time.time()

if __name__ == '__main__':
   target = input('Enter the host to be scanned: ')
   t_IP = gethostbyname(target)
   print ('Starting scan on host: ', t_IP)
   
   for i in range(50, 500):
      s = socket(AF_INET, SOCK_STREAM)
      
      conn = s.connect_ex((t_IP, i))
      if(conn == 0) :
         print ('Port %d: OPEN' % (i,))
      s.close()
print('Time taken:', time.time() - startTime)
Publisher
Latest posts by Publisher (see all)

Publisher

Publisher @ideasorblogs

Leave a Reply