Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this above one is sample logging.py above 2 is networking experimental. please show the 3 things needed like the first picture of the assignment python
this above one is sample logging.py
above 2 is networking experimental. please show the 3 things needed like the first picture of the assignment python
u can't see it?
1) Your python source code (.py file) 2) A screenshot of the output of your script 3) The resulting Log File pielogging.py III Python Logging. Example Professor Hosmer August 2020 import logging ---#-Python Standard - Logging Library # Turn-on-Logging I print(" Sample Python-Logging ") #logging. basicConfig(filename='Script.log',level=logging.DEBUG, format='%(asctime)s -%message)s') logging.basicConfig(filename='ScriptLog.txt',level=logging.DEBUG, format='%(asctime)s --%(process)d- %(levelname)s- %(message)s') logging.info('Script Started") logging.warning('Sample Warning Message -') logging.error("Sample - Error Message...) logging.critical('Sample Critical Message') print(" Script Complete") HII 2 - Sample NTP Request using pool.ntp.org 3 Professor Hosmer -- Experimental Script 5 6 7 from contextlib-import closing # import the closing method from the context library 8 from socket import socket, AF_INET, SOCK_DGRAM # import needed methods and attributes from the socket library 9 10 import sys#import-sys library 11 import struct # import struct. library 12 import time import the time-library 13 import logging 14 15 #. Psuedo Constants 16 NTP_PACKET_FORMAT="1121" #defines the expected format of the receive packet-from-pool.ntp.org 17 NTP_DELTA = 2208988808 -#- For Windows 1970-01-01 00:00:00 - epoch value 18 NTP_QUERY = -b'\x1b'+47*b'\B'--1b-hex-followed-by-47-ee-bytes 19 20 SECONDS - 10 # Offsets into the response - buffer 21 MICRO_SECONDS = 11 22 23 URL ="pool.ntp.org" # URL-to-the-Pool-of-synchronized. NTP-Servers 24 PORT... = 123 # NTP-Protocol. Port. Number 25 26 if _name__ == "_main_": 27 ""Main Script Entry Point." 28 29 print(" Get Network Time version 1.0- ") 30 31 while - True: 32 with closing(socket(AF_INET, SOCK_OGRAM)) as s: # Open-a-Socket and close automatically once completed 33 S.sendto(NTP_QUERY, (URL, PORT)) 34 # Send the NTP Query to pool.ntp.org .... msg, address = s.recvfrom(1024) 35 # Wait for the response 36 -#- unpack the results using struct and the known format 37 #which is Big Endian (1) 12 Unsigned Integers (4 bytes each) 38 unpackedResponse = struct.unpack(NTP_PACKET_FORMAT, msg[e: struct.calcsize(NTP_PACKET_FORMAT)]) 39 40 41 -For our purpose the unpacked response values 42 offset(10) = Seconds 43 offset(11) = MicroSeconds 44 45 46 Seconds****float(unpackedResponse (SECONDS)) 47 microseconds 48 = float(unpackedResponse(MICRO_SECONDS]) / 2**32 49 50 to calcuate the final epoch value we need to 51 combine the seconds and microseconds and deduct the NTP_DELTA 52 note, the NTP Delta for Windows is the epoch value from January 1, 1970 503 53 54 epoch = seconds + microseconds - NTP_DELTA Select Python Interpreter AO . timeValue = time.gmtime(epoch) #. Convert to UTC Time Value ................................ #Then convert to human-readable form humanReadable = time.strftime("%m/%d/%Y-%H:%M:%S UTC", timeValue) print(humanReadable) # Print Human Readable Value 64 65 66 67 ans = input(" Enter R to Retry: .") if ans.upper() == 'R': - continue else: -break 68 print(" Script. Terminated by User ...") 69 This week you will work again with the NetwrokTime-Experimental script. You will then add detailed Cyber Operations Logging to the script using SampleLogging.py as a reference. Your log file should include information, warnings and critical information based on your additional logging events. For example, if you cannot open a file, raise an informational logging event. If you encounter a hash, file name, or extension match, raise a critical logging event. You will submit 3 files. 1) Your python source code (.py file) 2) A screenshot of the output of your script 3) The resulting Log FileStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started