Activity 9.3 - Ping-ing a website

Topic

In this activity we use a test program called ping to make contact with some web sites and investigate their internet addresses. We also use a small Java program to find out the host name and internet address of our own computer.

Materials

In addition to the Solution document, the project for this exercise contains one class, which is complete:

Task

You are to make contact with various websites using the ping program. Then you are to run the HostNameFinder class to discover the symbolic name of your own computer and use it to ping yourself.

Instructions

  1. You will need to be connected to the Internet before you begin. Open a Command Prompt window. (On Windows you would typically do this by clicking Start, then Programs, Accessories, Command Prompt, but the exact details may vary depending on your operating system.) At the prompt type

    ping www.google.co.uk

    and then press enter. You should see that four packets of data have been sent to the remote web server, and with luck four replies have been received!

    You should see that ping reports some statistics for the time taken for the data to get there and back. Notice also that it has found out the numerical IP address corresponding to the symbolic name www.google.co.uk. If you now try pinging this IP address instead of the name you should find that it works exactly the same as the symbolic equivalent. You may also find that when you ping a particular name the request is actually redirected to a different name. This is quite common.

  2. At this point you may like to try pinging some other sites and seeing how long the round trip takes. The ping may not always work; sometimes a request can time out. Some sites do not respond to ping messages.

  3. Run the project containing the class HostNameFinder. The output will display a symbolic name for your computer. Now try pinging yourself, by entering ping followed by the name you have just found, at the command prompt. You should find that the return trip takes very little time! You will also be able to discover your own numerical IP address (and you can try pinging that if you want!)

Note

With some internet connections if the connection is active the name returned by HostNameFinder does not work and the ping program reports that the request has timed out. If this happens the simplest thing is to ping the symbolic name localhost instead.