The difference between ASP.net getremoteaddr () and Getremotehost () _jsp programming
Source: Internet
Author: User
GETREMOTEADDR (): Obtain the client's IP address
Getremotehost (): Get the name of the client computer, if it fails, return the IP address of the client computer
InetAddress ia = Inetaddress.getlocalhost ();
String iad = ia.gethostaddress ();//Host IP
String IAS = Ia.gethostname ();//Host Name
May I use the following statement in the JSP page:
System.out.println ("Request.getremoteaddr ():" + request.getremoteaddr ());
System.out.println ("Request.getremotehost ():" + request.getremotehost ());
The results obtained are the same (results of the test in the LAN).
So what's the difference between getremoteaddr () and Getremotehost ()?
The previous one is to obtain the client's IP address
The latter one is to obtain the client's host name
So use the previous one.
Using REQUEST.GETREMOTEADDR () to get client IP is a problem
REQUEST.GETREMOTEADDR () can get the client IP, but the result I tried was 0:0:0:0:0:0:0:1, please ask where the problem is and how to solve it? Thank you for your answer.
This may be because you are not connected to the Internet or LAN do not have access to IP, but also may be your way to the Internet has a problem, I have been out of this problem, but in exchange for the company to use the LAN test IP on display
How can I get a real client IP address in the servlet?
If the client is from a network segment other than the server, REQUEST.GETREMOTEADDR get only that client Gateway (proxy) IP, no way to access the real client IP?
When a user uses an agent or a LAN to access your application, you use the Request.getremoteaddr () method to return the address of the proxy or the address of the LAN gateway.
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.