In the article "four static methods for creating InetAddress objects", get the four IP addresses corresponding to www.csdn.net through getAllByName. Theoretically, entering one of the four IP addresses in the address bar of IE (or another Web browser, such as Firefox) may access www.csdn.net. For example, enter http: // 211.100.26.124. However, IE returns an error message. After you enter the other three IP addresses, the same error message is returned.
This error does not mean that the webpage does not find an error (HTTP status code: 404), but rejects the access error (HTTP status code: 403 ). When you enter a http://www.csdn.net in the address bar, you can still access this website. From the above indications, this is not a client issue, but a server limit.
There is a Host field in the request header of the HTTP protocol (which will be detailed in the next chapter). Generally, when accessing the server through the http://www.csdn.net, the Host value is www.csdn.net. For http: // 211.100.26.124, the Host value is 211.100.26.124. Therefore, we can infer that the server www.csdn.net can detect the Host field to prevent clients from directly using IP addresses for access. There are many websites such as www.sina.com.cn and www.126.com. Some websites do not use IP addresses for access, but when using IP addresses to access the website, the IP addresses are relocated to the corresponding domain names. If you enter http: // 141.146.8.66, it will be relocated to html "> callback.
The ping Command can also be used to obtain the IP address of a domain name. If the domain name is bound with an IP address, DNS returns an IP address at random. For example, enter the following command in the console:
Ping www.csdn.net
Returned results
Reply from 211.100.26.122: bytes = 32 time = 31 ms TTL = 48
Reply from 211.100.26.122: bytes = 32 time = 35 ms TTL = 48
The IP address in the returned result above is the third IP address obtained by MyInetAddress3 in Test 1 in "four static methods for creating InetAddress objects.