Voip.ms latency measurement, Part 2 =================================== Contents -------- .. toctree:: :maxdepth: 1 Indices and tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` Background ---------- This week, the goal is to ping the voip servers. To learn about ping, open up Konsole and type `man ping`. You can try to ping the local host as an example, `ping -c 4 localhost` However, you won't be able to ping externally (on a Wescam asset) due to the firewall. So, we will use a web server to do the pinging for us. The server is at `http://ec2-35-168-148-68.compute-1.amazonaws.com/`, to see an example return try querying it with a host like `python.org `_ Exercise -------- For this week, the goal is to create a Ping Request :py:keyword:`class` that will do the following: * It should store the ip or dns address of the server. * It should contain a method to send a ping request: * The method should accept a parameter that is the host name to ping * The method should send a http GET request to the server * This request should only include the desired ping target, in our case the host name * The method should check that the server response has a status of 200 * The method should return the server response. This will require using the :py:mod:`requests` library again. You will likely want to use :py:func:`requests.get` On completion of this exercise, you should be able to run your stub program and have it do the following: * Print a list of voip.ms server host names * For each host name, print the response recieved from the server after sending a request with the host name. Hints ----- Here is the class definition, as well as signatures for the constructor and function to send the http requests .. literalinclude:: voip2.py :language: python3 :lines: 40-50, 53-58 For reference, the code running on the web server is below: .. literalinclude:: ../ping_server/ping_server.py :language: python3 :emphasize-lines: 27,44 * The server is located at IP: 35.168.148.68 or DNS: ec2-35-168-148-68.compute-1.amazonaws.com. It is on the http port (80), which means you don't have to worry about including the number. * You can provided requests with either the IP or DNS address, however using the DNS can be significantly slower to access. (Give it a try!) * The server response will be a json object, you will need to convert it. Solution -------- When you are ready to see one possible solution, try :download:`this file `