Vous êtes sur la page 1sur 10

Understanding Basic Network Terms like: IP, TCP/IP, DNS, DHCP and more.

Most of these exercises are meant to be answered in text, so write down your replies so you will
remember.

1. What is your public IP address right now, and how did you find it?
www.whatismyip.com -> 91.100.103.58 / 5.179.80.204

2. What is your private IP address right now (do this both at home and in school), and who/what gave
you that address?
command konsol – ipconfig – find ivp4: 10.50.137.120
Local Home ip: 192.168.1.2
Routeren dedikerede computeren en IP adresse.
3. What’s special about these address ranges?
 10.0.0.0 – 10.255.255.255 – 16 millioner addresser 24 bit
 172.16.0.0 – 172.31.255.255 - 1 million 20 bit – loopback adressen
 92.168.0.0 – 192.168.255.255 – 65000 16 bit
4. What’s special about this ip-address: 127.0.0.1? adresse som reffererer til den computer
man sidder ved. localhost
5. What kind of service would you expect to find on a server using these ports: 22, 23, 25, 53,
80, 443? Ssh, telnet, SMTP, DNS, HTTP, HTTPS
6. What is the IP address of studypoints.dk and how did you find it?
Ipinfo.info -> 176.9.147.60
7. If you write https://studypoints.dk in your browser, how did “it” figure out that it should go
to the IP address you discovered above?
Computeren bruger en DNS server for at slå det domain op man prøver forbinde adgang til.
Det kaldes DNS name resolution og DNS serveren resolver domainet til en IP adresse.
8. Explain shortly the purpose of an ip-address and a port-number and why we need both
Alle enheder som er forbundet til et netværk har en numerisk label tilknyttet som bruges til
enten at hoste eller netværk interface identifikation og adresse lokation.
Porte er interfaces mellem to computere eller enheder som er forbundet.
9. What is your (nearest) DNS server,?
10. 192.168.1.1 SYS
11. What is (conceptually) the DNS system and the purpose with a DNS Server? DNS system: DNS
server er placeret på et IP baseret datanet og oversætter alle domains til IP adresser. DNS server kan enten
oversætte mellem ip adresser og domænenavne, eller kontakte andre servere for at få en adresse oversat.
12. What is your current Gateway, and how did you find it?
Netværksinstillinger - > 192.168.1.1
13. What is the address of your current DHCP-Server, and how did you find it?
Netværksinstillinger -> 192.168.1.1
14. Explain (conceptually) about the TCP/IP-protocol stack
Videregivelse af data på et netværk bliver udført i lag, hvor hver protocol i hvert lag gør
noget samtidig med de andre lag. De lag kaldes protocol stack. TCP er transport lag og ip er
netværkslaget.
15. Explain about the HTTP Protocol (the following exercises will go much deeper into this
protocol) Http er en asymetrisk request – response clientserver protocol. En HTTP client sender et request
tile n HTTP server hvorefter serveren sender et response tilbage til clienten. Også kaldet en pull protocol.
16. Explain (conceptually) how HTTP and TCP/IP are connected (what can HTTP do, and where
does it fit into TCP/IP)

HTTP er standard applikations protokollen oven på TCP/IP som håndterer web browser
requests og responses. Browsers og serverer kommunikerer via TCP/IP protokoller.

En standard web session foregår således:

 En bruger specificerer en URL i browseren


 Browseren initierer en TCP forbindelse til web serveren (port 80 default) via dens IP adresse som er
oplyst fra DNS serveren som laver et request på det domæne.
 Serveren godkender forbindelsen og browseren sender et request til serveren om at hente dataen /
oplysningerne.
 Serveren svarer tilbage med indholdet fra websiden, browseren modtager det fra http pakkerne og
fremviser det.

1) Monitoring HTTP Headers 1


Create a new NetBeans Maven Web-project.
For this exercise we will just use the default index.html generated by NetBeans.

Press the run button. When the file is shown in the browser (Chrome), open the network tab in the
developer window (Ctrl-shift-j) and press F5

Observe and explain each of the values monitored (use view source to see the plain messages).

Hints: In order to better observe the values related to Caching you might need to:

Go back to NetBeans and rename your file to index1.html

Go back to your browser and (while the developer window is open) change the url to point to the new file.

Observe the values

Press F5 and observe the values again.

Explain what you see.

En ny request bliver hele tiden sent med pakker og mængden stiger.

2) Monitoring HTTP Headers 2

Add an image to the page

Add an external style sheet to the page (<link rel="stylesheet" type="text/css" href="myStyle.css">)

Reload the page again, observe the request(s) being made, and explain the purpose of the Connection:
header.
Vi beder nu om at få et request på det billede vi har indsat og stylesheet. Der sendes nu 5 pakker i
alt.

Connection header viser os status på den request vores computer sender til serveren, samt det response
der sendes som pakker tilbage.

3) Monitoring HTTP Headers 3 (Response-codes 3xx)


In the Web-project, created for 1+2, add a new HTML-page called r.html and add this text in an h1-tag “You
got redirected to me”.

Use the Wizard to create a servlet called redirect

Remove the processRequest and the doPost method completely from the generated servlet-code.

In the doGet(..) method replace the call to processRequest with this line:
response.sendRedirect("r.html");

While your server is running, open a (Chrome) browser, and in this, open Chrome Developer Tools and the
network tab.

Enter the address for the servlet (http:localhost:8080/redirect) into the browser and explain:

 The two http-request you see


Der er først et generelt request på den url vi beder om:
r.html = http://localhost:8080/WebApplication1/r.html
Request metoden GET som requester en representation af den specifikke resource.
Status coden: 304 (det er en redirect kode) som gik godt
Remote address: localhost
Og så en request header hvor connection står til keep alive.
 How the browser knew where to go in the second request

Computeren sender en request via browseren (url’en http), og metoden GET til serveren. I vores
servlet håndterer doGet() metoden hvor vi sendes hen som redirecter os til r.html når vi indtaster
url’en http://localhost:8080/WebApplication1/redirect.

Vi requestede at gå til redirect, men blev sendt til r.html.

3a) Redirecting to https instead of http

In Google Chrome enter this address (with the developer window + the network-tab open), and exactly as
it is spelled):
http://studypoints.dk:

Explain the first two request monitored (notice where you requested to go, and where you actually ended).

Important: Later this week, you will learn how to setup your own server to use https, and ONLY https.

Den ene studypoints.dk request har en General header som via metoden GET laver et internal redirect
(code 307) til response header med lokation studypoints.dk. Forskellen ligger i den først requester http og
derefter kommer med response til HTTPS.

4a) Status Codes (5xx)


Use the Wizard to create a servlet called ups

In the processRequest(..) method, just before the try-statement add this code:

int result = 100/0;

While your server is running, open open Chrome developer tools and the network tab and call the servlet.

Write down the response code generated by the server as for the previous exercises

Response from ups:

1. Request URL:

http://localhost:8080/WebApplication1/ups

2. Request Method:

GET

3. Status Code:

500 Internal Server Error

4. Remote Address:

[::1]:8080

5. Referrer Policy:

no-referrer-when-downgrade

4b) Status Codes (4xx)


While your server is running, open open Chrome developer tools and the network tab, and call this address:
http://localhost:8080/i_dont_exist

Write down the response code generated by the server as for the previous exercises
1. Request URL:

http://localhost:8080/i_dont_exist

2. Request Method:

GET

3. Status Code:

404 Not Found

4. Remote Address:

[::1]:8080

5. Referrer Policy:

no-referrer-when-downgrade

4c) Status Codes - Ranges

Your document, containing the Status Codes for all the exercises done so far, should now contain codes like
2xx, 3xx, 4xx and 5xx.

Explain (write down your answer so you won’t forget) the meaning of the first digit in the 3-digit Status
Codes you have seen so far.

200: Et request sendes til servletten og response gives tilbage om et succesfuldt url svar.

302: opstår når der sker en url redirection. Dvs den url man requester giver et redirect (response) til en
anden url.

404: et standart http svar (response) om at serveren ikke kan finde den url der blive requested.

500: der er en fejl på website’s server (internal error) og den kan ikke informere om hvad der gik galt.

6) Get HTTP Request Headers on the Server


We have seen that a HTTP request from a Browser typically includes a lot of headers with information
related to the client.

This information is available to a servlet (is available to any web-server technology) via the request object.
Create a Servlet, which should output this information in a table as sketched in this figure (or in any way
you like, but don’t focus on presentation).

Hints: Use the request objects getHeaderXXX methods.

SVAR: http://localhost:8080/WebApplication1/getHeader

5) Get/Post-parameters
Create a new html-file in the web-project made in exercise 1.

Add a form to the file, including two text input boxes and a submit button as sketched below:

Add an extra input field to the form with type=”hidden”, name=”hidden” and value=12345678.

Add the value “#” for the forms action attribute.

Set the forms method-attribute to the value “GET” (actually the default value) and test the form. Observe
what happens in your browser's address field.

Change the forms method-attribute to the value “POST” and test the form. Observe the change in your
browsers address field. Figure out (using Chrome Developer Tools), how parameters are passed in, for a
POST request.
Write down your observations
Metoden GET angiver key values i den indtastede url.

Ved at bruge metoden POST fremvises kun det # som vi angav i form actionen i url’en.

Under NETWORK -> HEADERS kan man se en FORM DATA (et dokument), efter alle headers, hvori alle key
values ligger.

Session and Cookies


For the next two exercises/demos you should create a new web-project.

Both the demos uses a Servlet.

7) Sessions (Session Cookies)


In your web project use the wizard to generate a new Servlet

a. Enter SessionDemo as the name of the Servlet and servlets as package name
b. Right click the file and select Run to see “what is does”
c. Change the generated processRequest(..) method as sketched below.

protected void processRequest(HttpServletRequest request,


HttpServletResponse response)
throws ServletException, IOException {
String name = request.getParameter("name");
if (name != null) {
request.getSession().setAttribute("name", name);
} else {
name = (String) request.getSession().getAttribute("name");
}
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet SessionDemo</title>");
out.println("</head>");
out.println("<body>");
if (name != null) {
name = (String)request.getSession().getAttribute("name");
out.println("<p> Welcome " + name + " !</p>");
} else {
out.println("<h2>Please enter your name, and submit</h2>");
out.println("<form action='SessionDemo'>");
out.println("<input type='input' name='name'>");
out.println("<input type='submit'></form>");
}
out.println("</body>");
out.println("</html>");
}
}

d. Enter your name and press submit, copy the URL in the browser into your clipboard, close the
tab (but not the browser) and load the page again in a new tab using the URL in the clipboard.
e. While doing the things in step d, you should monitor the content of your local
cookies and the HTTP requests being sent, using the development tools in Chrome.
f. Most import part of this exercise:
Explain (on paper) using both words and images how the Server can maintain state between
subsequent calls even when the state is not transmitted from the client to server.
Når Martin indtastes bliver der genereret en sessioncookie og state står på keep alive. Nu ligger den
sessioncookie på computeren og hver gang vi taster en ny URL med
http://localhost:8080/CookieExercise/SessionDemo?name=Martin så kan vi se under cookies at der
requestes en cookie, men der genereres ikke en ny. Derved gemmes vores session i en sessioncookie.

Write down your observations


8) Persistent Cookies
a. In your web project use the wizard to generate a new servlet
b. Enter CookieDemo as the name of the Servlet and servlets as package name
c. Change the generated processRequest(..) method as sketched below.

protected void processRequest(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {
String name = request.getParameter("name");
if (name != null) {
Cookie cookie = new Cookie("username", name);
cookie.setMaxAge(60 * 60 * 24 * 365);
response.addCookie(cookie);
}
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : request.getCookies()) {
if (cookie.getName().equals("username")) {
name = cookie.getValue();
}
}
}
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet CookieDemo</title>");
out.println("</head>");
out.println("<body>");
if (name != null) {
out.println("<p> Welcome " + name + " !</p>");
} else {
out.println("<h2>Please enter your name, and submit</h2>");
out.println("<form action='CookieDemo'>");
out.println("<input type='input' name='name'>");
out.println("<input type='submit'></form>");
}
out.println("</body>");
out.println("</html>");
}
}

d. Enter your name and press submit, copy the URL in the browser into your clipboard, close the
tab (but not the browser) and load the page again in a new tab using the URL in the clipboard.
e. Now close your browser (you could even close your laptop, but don’t ;-) , open it
again and load the page again using the URL in the clipboard
f. While doing the things in step e, you should monitor the content of your local
cookies and the HTTP requests being sent, using the development tools in Chrome.
g. Most import part of this exercise:
h. Explain (on paper) how Cookies can be used to maintain “state” on the client
between subsequent calls to a server, even when a browser has been closed down.

Write down your observations


Vi får først en cookie kaldet USERNAME med value Martin.

I den nye tab skriver vi http://localhost:8080/CookieExercise/CookieDemo?name=Martin og kan se under


NETWORK -> Cookies at den requester en cookie og response er en cookie med expiration date 2019-30-08.
Dvs den cookie har en udløbsdato om et år.

Vous aimerez peut-être aussi