计网 Lab1

Lab1

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

在这里插入图片描述

在这里插入图片描述


  • 9
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值