Lab1
- Part1: Simple Socket Program (TCP)
- Part2: HTTP
- The Basic HTTP GET/response interaction
- 1. Is your browser running HTTP version 1.0, 1.1, or 2? What version of HTTP is the server running?
- 2. What languages (if any) does your browser indicate that it can accept to the server?
- 3. What is the IP address of your computer? What is the IP address of the gaia.cs.umass.edu server?
- 4. What is the status code returned from the server to your browser?
- 5. When was the HTML file that you are retrieving last modified at the server?
- 6. How many bytes of content are being returned to your browser?
- 7. By inspecting the raw data in the packet content window, do you see any headers within the data that are not displayed in the packet-listing window? If so, name one.
- The HTTP CONDITIONAL GET/response interaction
- 8. Inspect the contents of the first HTTP GET request from your browser to the server. Do you see an “IF-MODIFIED-SINCE” line in the HTTP GET?
- 9. Inspect the contents of the server response. Did the server explicitly return the contents of the file? How can you tell?
- 10. Now inspect the contents of the second HTTP GET request from your browser to the server. Do you see an “IF-MODIFIED-SINCE:” line in the HTTP GET? If so, what information follows the “IF-MODIFIED-SINCE:” header?
- 11. What is the HTTP status code and phrase returned from the server in response to this second HTTP GET? Did the server explicitly return the contents of the file? Explain.
- Retrieving Long Documents
- 12. How many HTTP GET request messages did your browser send? Which packet number in the trace contains the GET message for the Bill or Rights?
- 13. Which packet number in the trace contains the status code and phrase associated with the response to the HTTP GET request?
- 14. What is the status code and phrase in the response?
- 15. How many data-containing TCP segments were needed to carry the single HTTP response and the text of the Bill of Rights?
- HTML Documents with Embedded Objects
- HTTP Authentication
- Part3: DNS
- nslookup
- 1. Run nslookup to obtain the IP address of the web server for Fudan University: https://www.fudan.edu.cn.What is the IP address of fudan.edu.cn?
- 2. What is the IP address of the DNS server that provided the answer to your nslookup command in question 1 above?
- 3. Did the answer to your nslookup command in question 1 above come from an authoritative or non-authoritative server?
- 4. Use the nslookup command to determine the name of the authoritative name server for the fudan.edu.cn. What is that name? (If there are more than one authoritative servers, what is the name of the first authoritative server returned by nslookup)? If you had to find the IP address of that authoritative name server, how would you do so?
- The DNS cache on your computer
- Tracing DNS with Wireshark
- visit Web page: https://www.fudan.edu.cn/
- 5. Locate the first DNS query message resolving the name fudan.edu.cn. What is the packet number in the trace for the DNS query message? Is this query message sent over UDP or TCP?
- 6. Now locate the corresponding DNS response to the initial DNS query. What is the packet number in the trace for the DNS response message? Is this response message received via UDP or TCP?
- 7. What is the destination port for the DNS query message? What is the source port of the DNS response message?
- 8. To what IP address is the DNS query message sent?
- 9. Examine the DNS query message. How many “questions” does this DNS message contain? How many “answers” answers does it contain?
- 10. Examine the DNS response message to the initial query message. How many “questions” does this DNS message contain? How many “answers” answers does it contain?
- nslookup fudan.edu.cn
- 11. What is the destination port for the DNS query message? What is the source port of the DNS response message?
- 12. To what IP address is the DNS query message sent? Is this the IP address of your default local DNS server?
- 13. Examine the DNS query message. What “Type” of DNS query is it? Does the query message contain any “answers”?
- 14. Examine the DNS response message to the query message. How many “questions” does this DNS response message contain? How many “answers”?
- nslookup -type=NS fudan.edu.cn
- 15. To what IP address is the DNS query message sent? Is this the IP address of your default local DNS server?
- 16. Examine the DNS query message. How many questions does the query have? Does the query message contain any “answers”?
- 17. Examine the DNS response message. How many answers does the response have? What information is contained in the answers? How many additional resource records are returned? What additional information is included in these additional resource records?
Part1: Simple Socket Program (TCP)
Code & Description
client.java
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) {
String serverAddress = "127.0.0.1";
int serverPort = 12345;
try {
// 创建TCP套接字
Socket clientSocket = new Socket(serverAddress, serverPort);
// 获取输入流和输出流
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// 发送用户输入的字符串
System.out.print("请输入要发送的字符串:");
String message = inFromUser.readLine();
outToServer.writeBytes(message + '\n');
// 接收服务器返回的消息
String response = inFromServer.readLine();
System.out.println("服务器返回的消息:" + response);
// 关闭套接字
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
server.java
import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) {
int serverPort = 12345;
try {
// 创建TCP欢迎套接字
ServerSocket welcomeSocket = new ServerSocket(serverPort);
System.out.println("服务器正在监听连接请求...");
while (true) {
// 接受客户端连接请求
Socket connectionSocket = welcomeSocket.accept();
System.out.println("与客户端连接成功:" + connectionSocket.getInetAddress().getHostAddress() + ":" + connectionSocket.getPort());
// 获取输入流和输出流
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
// 接收客户端发送的字符串
String message = inFromClient.readLine();
System.out.println("接收到客户端发送的字符串:" + message);
// 将字符串转换为大写
String modifiedMessage = message.toUpperCase();
// 返回修改后的字符串给客户端
outToClient.writeBytes(modifiedMessage + '\n');
// 关闭与客户端的连接
connectionSocket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Screenshot of code running
Part2: HTTP
The Basic HTTP GET/response interaction
1. Is your browser running HTTP version 1.0, 1.1, or 2? What version of HTTP is the server running?
Answer: both 1.1 (another screenshot can be seen in question 4 below)
2. What languages (if any) does your browser indicate that it can accept to the server?
Answer: zh-CN, zh
3. What is the IP address of your computer? What is the IP address of the gaia.cs.umass.edu server?
Answer:
My Computer : 192.168.31.190
gaia.cs.umass.edu Server : 128.119.245.12
4. What is the status code returned from the server to your browser?
Answer: 200
5. When was the HTML file that you are retrieving last modified at the server?
Answer: Sun, 29 Oct 2023 09:56:30 GMT
6. How many bytes of content are being returned to your browser?
Answer: 128 bytes
7. By inspecting the raw data in the packet content window, do you see any headers within the data that are not displayed in the packet-listing window? If so, name one.
Answer: Content-Type
The HTTP CONDITIONAL GET/response interaction
8. Inspect the contents of the first HTTP GET request from your browser to the server. Do you see an “IF-MODIFIED-SINCE” line in the HTTP GET?
Answer: No
9. Inspect the contents of the server response. Did the server explicitly return the contents of the file? How can you tell?
Answer: Yes. Because I can see it. (shown in the following screenshot)
10. Now inspect the contents of the second HTTP GET request from your browser to the server. Do you see an “IF-MODIFIED-SINCE:” line in the HTTP GET? If so, what information follows the “IF-MODIFIED-SINCE:” header?
Answer: Yes. If-Modified-Since: Sun, 29 Oct 2023 05:59:02 GMT\r\n
11. What is the HTTP status code and phrase returned from the server in response to this second HTTP GET? Did the server explicitly return the contents of the file? Explain.
Answer:
status code and phrase : 304 Not Modified
No.
Reason: When the browser successfully accesses the target website for the first time, it caches the webpage content. In subsequent visits, if the website content has not been updated, the browser retrieves the content directly from its cache, eliminating the need for the server to return the actual file content.
Retrieving Long Documents
12. How many HTTP GET request messages did your browser send? Which packet number in the trace contains the GET message for the Bill or Rights?
Answer:
1 request message.
Packet number : 10389
13. Which packet number in the trace contains the status code and phrase associated with the response to the HTTP GET request?
Answer: 10679 (screenshot : same as question 12 above)
14. What is the status code and phrase in the response?
Answer: 200 OK
15. How many data-containing TCP segments were needed to carry the single HTTP response and the text of the Bill of Rights?
Answer: 4
HTML Documents with Embedded Objects
16. How many HTTP GET request messages did your browser send? To which Internet addresses were these GET requests sent?
Answer:
3 request messages (whose packet number is 159, 173 and 190)
packet number 159 : http://gaia.cs.umass.edu/wireshark-labs/HTTP-wireshark-file4.html
packet number 173 : http://gaia.cs.umass.edu/pearson.png
packet number 190 : http://kurose.cslash.net/8E_cover_small.jpg
17. Can you tell whether your browser downloaded the two images serially, or whether they were downloaded from the two web sites in parallel? Explain.
Answer: serially
Because the download of the second image is requested only after receiving a response to the download request for the first image, so two images are downloaded serially.
HTTP Authentication
18. What is the server’s response (status code and phrase) in response to the initial HTTP GET message from your browser?
Answer: 401 Unauthorized
19. When your browser’s sends the HTTP GET message for the second time, what new field is included in the HTTP GET message?
Answer: Authorization : Basic
(which is associated with username and password)
Part3: DNS
nslookup
1. Run nslookup to obtain the IP address of the web server for Fudan University: https://www.fudan.edu.cn.What is the IP address of fudan.edu.cn?
Answer: 202.120.224.81
2. What is the IP address of the DNS server that provided the answer to your nslookup command in question 1 above?
Answer: 192.168.31.1(screenshot : same as question 1 above)
3. Did the answer to your nslookup command in question 1 above come from an authoritative or non-authoritative server?
Answer: From an authoritative server
4. Use the nslookup command to determine the name of the authoritative name server for the fudan.edu.cn. What is that name? (If there are more than one authoritative servers, what is the name of the first authoritative server returned by nslookup)? If you had to find the IP address of that authoritative name server, how would you do so?
Answer:
ns.fudan.edu.cn(screenshot : same as question 3 above)
type the command
nslookup ns.fudan.edu.cn
The DNS cache on your computer
Tracing DNS with Wireshark
visit Web page: https://www.fudan.edu.cn/
5. Locate the first DNS query message resolving the name fudan.edu.cn. What is the packet number in the trace for the DNS query message? Is this query message sent over UDP or TCP?
Answer:
Packet number : 74
UDP
6. Now locate the corresponding DNS response to the initial DNS query. What is the packet number in the trace for the DNS response message? Is this response message received via UDP or TCP?
Answer:
Packet number : 75
UDP
7. What is the destination port for the DNS query message? What is the source port of the DNS response message?
Answer:
Destination port for the DNS query message : 53
Source port of the DNS response message : 53
8. To what IP address is the DNS query message sent?
Answer: 192.168.31.1
9. Examine the DNS query message. How many “questions” does this DNS message contain? How many “answers” answers does it contain?
Answer:
Questions : 1
Answers : 0
10. Examine the DNS response message to the initial query message. How many “questions” does this DNS message contain? How many “answers” answers does it contain?
Answer:
Questions : 1
Answers : 1
nslookup fudan.edu.cn
11. What is the destination port for the DNS query message? What is the source port of the DNS response message?
Answer:
Destination port for the DNS query message : 53
Source port of the DNS response message : 53
12. To what IP address is the DNS query message sent? Is this the IP address of your default local DNS server?
Answer: 192.168.31.1 Yes
13. Examine the DNS query message. What “Type” of DNS query is it? Does the query message contain any “answers”?
Answer:
Type : A
Answers : 0
14. Examine the DNS response message to the query message. How many “questions” does this DNS response message contain? How many “answers”?
Answer:
Questions : 1
Answers : 1
nslookup -type=NS fudan.edu.cn
15. To what IP address is the DNS query message sent? Is this the IP address of your default local DNS server?
Answer: 192.168.31.1 Yes
16. Examine the DNS query message. How many questions does the query have? Does the query message contain any “answers”?
Answer:
Questions : 1
Answers : 0
17. Examine the DNS response message. How many answers does the response have? What information is contained in the answers? How many additional resource records are returned? What additional information is included in these additional resource records?
Answer:
Answers : 4
Information contained in the answers : shown in the last screenshot below
Additional resource records : 0
Additional information : none