Difference between asp.net getRemoteAddr () and getRemoteHost ()

Source: Internet
Author: User

GetRemoteAddr (): obtains the IP address of the client.
GetRemoteHost (): obtains the name of the client computer. If the name fails, the IP address of the client computer is returned.

InetAddress ia = InetAddress. getLocalHost ();

String iad = ia. getHostAddress (); // host IP Address
String ias = ia. getHostName (); // host name

I will use the following statement on the JSP page:
System. out. println ("request. getRemoteAddr ():" + request. getRemoteAddr ());
System. out. println ("request. getRemoteHost ():" + request. getRemoteHost ());
The results are the same (LAN test results ).
So what is the difference between getRemoteAddr () and getRemoteHost?

Obtain the IP address of the client.
The last one is to obtain the client host name.
So use the previous one.

Ask the client's ip address through request. getRemoteAddr ()

Request. getRemoteAddr () can be used to obtain the ip address of the terminal, but the result of my failed operation is 0: 0: 0: 0: 0: 0: 0: 1, where is the problem? How can I solve it? Thank you for your answers.



This may be because you have not connected to the Internet or the LAN and you have not obtained an ip address. It may also be because you have a problem with the way you access the internet, but switch to the company and use the LAN to test the ip address.

---------------------------------------------------------------

How can I obtain the real client IP address in servlet?
If the client comes from a CIDR block other than the server, request. getRemoteAddr only obtains the ip address of the client Gateway (proxy). Is there no way to obtain the real client ip address?

When you use a proxy or LAN to access your application, the request. getRemoteAddr () method returns the proxy address or the LAN gateway address.

Related Article

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.