getRemoteAddr(): Get the IP address of the client
getRemoteHost(): Get the name of the client computer. If it fails, return the IP address of the client computer.
InetAddress ia = ();
String iad = ();//Host IP
String ias = ();//hostname
I'm using the following statement in the JSP page:
("(): " + ());
("(): " + ());
The results obtained are the same (results of tests within the LAN).
So what is the difference between getRemoteAddr() and getRemoteHost()?
The previous one is to obtain the client's IP address
The latter is to obtain the host name of the client
So use the previous one.
There is a problem using() to get client's ip
() You can get the user ip, but the result I tried is 0:0:0:0:0:0:0:0:0:0:1. Please ask where is the problem and how to solve it? Thank you for your answers.
This may be because you are not connected to the Internet or the LAN does not get IP, or it may be because you have a problem with the Internet method. I have had such a problem, but when I switched to the company to use the LAN to test IP, it was displayed.
---------------------------------------------------------------
How can I get the real client IP address in a servlet?
If the client comes from a network segment other than the server, all he gets is the IP of the client gateway (agent). Can't he get the real client IP?
When a user uses a proxy or LAN to access your application, you use the () method to return the address of the proxy or the address of the LAN gateway.
getRemoteHost(): Get the name of the client computer. If it fails, return the IP address of the client computer.
InetAddress ia = ();
String iad = ();//Host IP
String ias = ();//hostname
I'm using the following statement in the JSP page:
("(): " + ());
("(): " + ());
The results obtained are the same (results of tests within the LAN).
So what is the difference between getRemoteAddr() and getRemoteHost()?
The previous one is to obtain the client's IP address
The latter is to obtain the host name of the client
So use the previous one.
There is a problem using() to get client's ip
() You can get the user ip, but the result I tried is 0:0:0:0:0:0:0:0:0:0:1. Please ask where is the problem and how to solve it? Thank you for your answers.
This may be because you are not connected to the Internet or the LAN does not get IP, or it may be because you have a problem with the Internet method. I have had such a problem, but when I switched to the company to use the LAN to test IP, it was displayed.
---------------------------------------------------------------
How can I get the real client IP address in a servlet?
If the client comes from a network segment other than the server, all he gets is the IP of the client gateway (agent). Can't he get the real client IP?
When a user uses a proxy or LAN to access your application, you use the () method to return the address of the proxy or the address of the LAN gateway.