{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 07: The Internet\n", "\n", "- **Name**: Domer McDomerson\n", "- **Netid**: dmcdomer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Activity 1: SpeedTest\n", "\n", "For the first activity, you are to measure the speed of various networking technologies by using the [SpeedTest] website. You are to use the following two connection types:\n", "\n", "1. **Wired or wireless connection from your laptop**\n", "\n", "2. **Cellular connection from your phone (make sure you are using 4G/LTE and not WiFi)**\n", "\n", "\n", "To test the speed of each connection, simply go to the website on the appropriate device: www.speedtest.net and hit the `Go` button. This will measure your **Ping**, **Download**, and **Upload** speeds to generate a result such as:\n", "\n", "\n", "\n", "\n", "[SpeedTest]: https://www.speedtest.net/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Speed Tests\n", "\n", "Run the [SpeedTest] on each connection type a few times to get a representative sample and then complete the table below:\n", "\n", "| Connection Type | Ping (ms) | Download (Mbps) | Upload (Mbps) |\n", "|-----------------|-----------|-----------------|---------------|\n", "| Laptop | 0 | 0.0 | 0.0 |\n", "| Phone | 0 | 0.0 | 0.0 |\n", "\n", "
Complete Table
\n", "\n", "[SpeedTest]: https://www.speedtest.net/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analysis\n", "\n", "After completing the table above with your speed tests, analyze the results by answering the following questions:\n", "\n", "1. Which connection type had the best **latency**? Explain.\n", "\n", " Response Here\n", "\n", "2. Which connection type had the best **bandwidth**? Explain.\n", "\n", " Response Here\n", " \n", "3. What difference (if any) did you notice between **download** and **upload** speeds? Discuss why this could be.\n", " \n", " Response Here\n", "\n", "4. Overall, which connection type was the **best**? Explain.\n", "\n", " Response Here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Activity 2: Bandwidth and Latency\n", "\n", "For the second activity, you are to write two functions that you can utilize to perform your own **bandwidth** and **latency** measurements. The first is `measure_bandwidth`, which uses [requests] to download data from a web server, while the second is `measure_latency` which uses a low-level [socket] to connect to a remote server. For timing, we will use Python's [time] module:\n", "\n", " current_time = time.time()\n", "\n", "[requests]: http://docs.python-requests.org/en/master/\n", "[socket]: https://docs.python.org/3/library/socket.html\n", "[time]: https://docs.python.org/3/library/time.html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Measure Bandwidth" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import requests\n", "import time\n", "\n", "def measure_bandwidth(url):\n", " ''' Measure bandwidth by doing the following:\n", " \n", " 1. Record start time.\n", " 2. Download data specified by url.\n", " 3. Record stop time.\n", " 4. Compute bandwidth:\n", " \n", " bandwidth = (Amount of Data / Elapsed Time)\n", " '''\n", " \n", " start_time = 0 # TODO: Record start time\n", " response = '' # TODO: Download data specified by url.\n", " stop_time = 0 # TODO: Record stop time\n", " bandwidth = 0 # TODO: Compute bandwidth\n", " return bandwidth / 2**20 # Convert to Megabytes per second" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloaded Slack with bandwidth of 0.00 MBps\n", "Downloaded Zoom with bandwidth of 0.00 MBps\n" ] } ], "source": [ "URLS = {\n", " 'Slack' : 'https://downloads.slack-edge.com/releases_x64/SlackSetup.exe',\n", " 'Zoom' : 'https://d11yldzmag5yn.cloudfront.net/prod/3.5.361976.0301/zoom_x86_64.tar.xz',\n", "}\n", "\n", "for app, url in URLS.items():\n", " bandwidth = 0 # TODO: measure bandwidth with url\n", " print(f'Downloaded {app} with bandwidth of {bandwidth:0.2f} MBps')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Measure Latency" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import socket\n", "import time\n", "\n", "def measure_latency(domain):\n", " ''' Measure latency by doing the following:\n", " \n", " 1. Create streaming internet socket.\n", " 2. Record start time.\n", " 3. Connect to specified domain at port 80.\n", " 4. Record stop time.\n", " 5. Compute latency:\n", " \n", " latency = Elapsed Time * 1000\n", " '''\n", " \n", " s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n", " start_time = 0 # TODO: Record start time\n", " s.connect((None, 0)) # TODO: Connect to specified domain at port 80.\n", " stop_time = time.time() # TODO: Record stop time\n", " return (stop_time - start_time) * 1000 # Convert to milliseconds" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Connection to facebook.com has latency of 0.00 ms\n", "Connection to cnn.com has latency of 0.00 ms\n", "Connection to google.com has latency of 0.00 ms\n", "Connection to nd.edu has latency of 0.00 ms\n", "Connection to amazon.co.uk has latency of 0.00 ms\n", "Connection to baidu.com has latency of 0.00 ms\n", "Connection to europa.eu has latency of 0.00 ms\n", "Connection to yahoo.co.jp has latency of 0.00 ms\n" ] } ], "source": [ "DOMAINS = [\n", " 'facebook.com',\n", " 'cnn.com',\n", " 'google.com',\n", " 'nd.edu',\n", " 'amazon.co.uk',\n", " 'baidu.com',\n", " 'europa.eu',\n", " 'yahoo.co.jp',\n", "]\n", "\n", "for domain in DOMAINS:\n", " latency = 0 # TODO: measure latency of domain\n", " print('Connection to {} has latency of {:0.2f} ms'.format(domain, latency))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analysis\n", "\n", "After writing the `measure_bandwidth` and `measure_latency` functions above and testing them, answer the following questions:\n", "\n", "1. Which applications had the best bandwidth? How do these bandwidth measurements compare to the ones you had in Activity 1? What explains the differences?\n", "\n", " Response Here\n", "\n", "2. Which domains had the best latency? Which ones had the worst latency? What explains these differences?\n", "\n", " Response Here" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python3", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" } }, "nbformat": 4, "nbformat_minor": 2 }