Saturday, 20 January 2018

opened ports on linux using python

#Python script for checking the list of opened ports in linux...

import socket,datetime
ip_list = open("ip_list.txt").readlines()
port_list = open("port_list.txt").readlines()
open_ports = []
failed_ports = []
def pscan(ips,ports):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.settimeout(2)
    try:
        con = s.connect((ips,ports))
        return True
    except:
        return False
print ('This Scan started on'), (datetime.datetime.utcnow() - datetime.timedelta(hours=5))
for ips in ip_list:
    for ports in port_list:
        con = pscan(str(ips.strip()),int(ports.strip()))
        if con == True:
            open_ports.append(ports.strip())
        else:
            failed_ports.append(ports.strip())
    print u"Device IP - " + ips.strip(), "Allowed", u"\u001b[32m" ,open_ports, u"\u001b[37m","Denied", u"\u001b[31m", failed_ports, u"\u001b[37m"
    open_ports = []
    failed_ports = []
print ('This Scan Ended on'),(datetime.datetime.utcnow() - datetime.timedelta(hours=5))

2 comments:

Bhanu Sree said...


well! Thanks for providing the information
Kubernetes Online Training
Docker Online Training

Lawway said...

We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming , aws training , ccna training (7+ years) will ensure that we will deliver our best in python training in chennai. , and we believe that no one matches us in this context.

ccna training in chennai
aws training in chennai
aws devops training in chennai
python training
python training in chennai

Prasanta Kumar Behera. Mob- 8147470101