Question: Write a python script that given 2 text files containing a list of ip addresses and a list of port numbers, respectively, can take that

Write a python script that given 2 text files containing a list of ip addresses and a list of port numbers, respectively, can take that information and verify if the services are up and running.

Problem 2:

Write a python script that given 1 text file containing a list of files and their paths can check the permissions for each file in the list.

these are the scripts I already have written

I just need help writing a IP address txt.file and a PORT txt.file so the scripts will run

from socket import *

def main(): ip_list = [ip_address.rstrip(' ') for ip_address in open('ip.txt')] port_list = [int(port_address.rstrip(' ')) for port_address in open('port.txt')] services = [(ip, port) for ip in ip_list for port in port_list] for service in services: s = socket(AF_INET, SOCK_STREAM) conn = s.connect(service) if conn == 0: print("Service on ip %s and port %s is up" % (service[0], service[1])) else: print("Service on ip %s and port %s is down" % (service[0], service[1])) s.close()

main()

Note: Save the code in a file. Save the files containing IP addresses and port as ip.txt and port.txt respectively in the same folder. On terminal type python3 filename.py to run the script.

Problem 2:

Write a python script that given 1 text file containing a list of files and their paths can check the permissions for each file in the list.

Solution:

import os

def main(): f = open('file_path.txt') for x in f: filename, filepath = x.split() if (os.access(filepath, os.R_OK)): print("%s is Readable" % filename) else: print("%s is not Readable" % filename) if (os.access(filepath, os.W_OK)): print("%s is Writable" % filename) else: print("%s is not Writable" % filename) if (os.access(filepath, os.R_OK)): print("%s is Executable" % filename) else: print("%s is not Executable" % filename)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!