top of page

Free Python Response Time Script Baseline And Calibration Using Wireshark

Writer: Tony FortunatoTony Fortunato

In this video you will see yet another example of baselining or calibrating an application reported results using Wireshark.


I am far from being a ‘programmer’ but have been programming since my college days in all sort of programming languages.


In the past 3 years, I have been moving away from Perl and getting more familiar with Python with no specific reason other than variety and for just my own personal education.

I wrote this script (with some help from ChatGPT and some snippets I found online that will record the TCP and HTTP response time, along with the current date/time and write it to a CSV format file.


I personally believe anyone in the technology space should be exposed to, and write the odd bit of code. It could be to automate a mundane task, performance measurements or anything you might need to accomplish that is specific to your environment.

 

Python script simply copy and paste the text between the ======  lines I called this script https_and_tcp_response time.py

#pip install requests

 

import socket

import ssl

import time

import requests

from datetime import datetime

 

def measure_tcp_response_time(hostname, port):

    start_time = time.time()

    sock = socket.create_connection((hostname, port))

    sock.close()

    end_time = time.time()

    return end_time - start_time

 

def measure_https_response_time(url):

    start_time = time.time()

    response = requests.get(url)

    end_time = time.time()

    return end_time - start_time

 

def main(url):

    hostname = url.split("//")[-1].split("/")[0]

    tcp_port = 443

   

    tcp_response_time = measure_tcp_response_time(hostname, tcp_port)

    https_response_time = measure_https_response_time(url)

    current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

 

    with open("response_times.txt", "a") as file:

        file.write(f"Time,TCP Response Time, HTTPS Response Time in seconds\n")

        file.write(f"{current_time},{tcp_response_time:.6f},{https_response_time:.6f}\n")

     

if name == "__main__":

    url = "https://www.thetechfirm.com"  # Replace with your desired URL

    main(url)

 

 




 

 


 
 
bottom of page