Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Code You have been hired as a threat detection analyst for a bank. Part of your job is inspecting IP logs to try to

Python Code

You have been hired as a threat detection analyst for a bank. Part of your job is inspecting IP logs to try to find any potential security threats. An IP version 4 address contains 4 octets of numbers between 0 and 255. They are in a format such as: 192.116.234.122

For purposes of this lab, all the IPv4 addresses have the full octet, even if the number starts with 0. As such, 78.82.123.145 would be stored as 078.082.123.145. Professor Offenberg teaches an excellent Ethical Hacking class here at HCC. Unfortunately, his evil twin brother, Darth Offenberg, is the head of the international crime group Offenberg's Unethical Computer Hackers (OUCH). Hackers from OUCH are trying to penetrate your system. OUCH always begin with one of three IP address ranges in the first two octets: 1. 168.193 2. 224.174 3. 233.012 You have been forwarded a file called "ipfile.txt". This file contains an unknown number of IP addresses and the data and time that the IP address accessed your system. Your job is to read the file, find all the suspect IP addresses that might have been used by OUCH, and produce an output report to both the screen and to an output file. 1. The program must allow the user to enter in the name of the input file: a. The program must call a function that receives the input filename as a parameter b. The program must use a try..except block to test that the file exists; if it does not exist, the program must display the appropriate error message and allow the reentry of the filename c. Once the program determines that the file exists, the function must return the file handle 2. The program must allow the user to enter in the name of the output file: a. The program must call the same function as above that receives the output filename as a parameter b. The program must use a try..except block to test that the file can be crated; if it cannot be created, the program must display the appropriate error message and allow the reentry of the filename c. Once the program determines that the file can be created, the function must return the file handle

3. The program must read all the data in the input file as strings: a. The program must keep a count of the total number of records in the file b. The program must create a list of strings that contains all the suspect IP Addresses; these are IP addresses that start with the values listed above c. Once the entire file is read, the program must close the file 4. The program must create and call a function to create the output report: a. The function must take the total number of records in the file, the list of suspect IP addresses and the output file handle as parameters b. The function must create the output report as displayed in the screen shot below; the output report MUST match the screen shot exactly c. The function must create the output file with the exact format as shown in the screen shot below; again, the output format must match the screen shot exactly d. The output report must contain the following: i. The number of records in the file ii. The number of suspect IP addresses (the number must be determined using a list function) iii. The percentage of IP addresses that are suspect (formatted to display to 3 decimal places) iv. The list of suspect IP addresses sorted by the IP address (the code must use a list function to perform this sort and string slicing to separate the IP address from the data and time stamp) e. The function must close the output file once the output report is complete f. NOTE - the file name prompts are NOT in the output file. Only the report information itself is in the output file. 5. The code must display an end of program message

Notes: 1. Submit the .py file and the "badip.txt" output file in Canvas. 2. Any actions involving the list must use list functions; the code MUST create a list of the suspect IP addresses 3. The output file must look exactly like this:

"ipfile.txt"

006.114.038.128 Thu Jul 7 09:50:43 2022 050.054.135.066 Thu Jul 7 09:50:43 2022 108.087.040.223 Thu Jul 7 09:50:43 2022 224.174.179.128 Thu Jul 7 09:50:43 2022 089.221.133.135 Thu Jul 7 09:50:43 2022 002.144.061.108 Thu Jul 7 09:50:43 2022 053.051.235.061 Thu Jul 7 09:50:43 2022 072.016.008.086 Thu Jul 7 09:50:43 2022 172.143.002.047 Thu Jul 7 09:50:43 2022 080.004.164.080 Thu Jul 7 09:50:43 2022 040.070.163.054 Thu Jul 7 09:50:43 2022 057.128.118.075 Thu Jul 7 09:50:43 2022 019.112.239.182 Thu Jul 7 09:50:43 2022 152.009.040.047 Thu Jul 7 09:50:43 2022 117.035.039.006 Thu Jul 7 09:50:43 2022 058.075.238.022 Thu Jul 7 09:50:43 2022 220.052.208.229 Thu Jul 7 09:50:43 2022 051.114.159.136 Thu Jul 7 09:50:43 2022 019.016.063.149 Thu Jul 7 09:50:43 2022 061.001.020.211 Thu Jul 7 09:50:43 2022 042.034.088.096 Thu Jul 7 09:50:43 2022 235.066.093.233 Thu Jul 7 09:50:43 2022 076.206.178.084 Thu Jul 7 09:50:43 2022 044.070.202.086 Thu Jul 7 09:50:43 2022

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions