Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions