Ava network programming from entry to mastery (3): Why cannot I access a website through IP address?

Source: Internet
Author: User

 


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 ingress.

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.