Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

Algorithm for file updates in Python

Early learning task completed in Google Cyber Security course

Project Description

You are a security professional working at a health care company. As part of your job, you're required to regularly update a file that identifies the employees who can access restricted content. The contents of the file are based on who is working with personal patient records. Employees are restricted access based on their IP address. There is an allow list for IP addresses permitted to sign into the restricted subnetwork. There's also a remove list that identifies which employees you must remove from this allow list. Your task is to create an algorithm that uses Python code to check whether the allow list contains any IP addresses identified on the remove list. If so, you should remove those IP addresses from the file containing the allow list.

Open the file that contains the allow list

The file containing the permitted employee IP addresses (allow_list.txt) must be opened in read mode ("r") to access its contents: 1

Read the file contents

The entire contents of the allow list file are read into a single string variable (ip_addresses): 2

Convert the string into a list

The string containing all IP addresses is converted into a list of individual strings using the .split() method: 3

Iterate through the remove list

A for loop is initiated to iterate over the items in the ip_addresses list. To safely remove elements within the loop, the iteration is performed over a copy of the list:

4

Remove IP addresses that are on the remove list

A conditional if statement checks if the current element (IP address) exists within the remove_list. If a match is found, the IP address is removed from the original ip_addresses list using the .remove() method: 5

Update the file with the revised list of IP addresses

To finalize the update, the filtered list is converted back into a single, space-separated string using the .join() method. The original file is then opened in write mode ("w") to overwrite its entire content with the revised list. 6

Summary

The entire logic is encapsulated into a reusable Python function, This function automates the security task of ensuring only currently authorized employees have IP access to the restricted subnetwork containing personal patient records.

Here is the entire Python code as a whole below:

All

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors