Hey i tried to get the ip of the client with ktor.
I used the method
this.context.request.local.remoteHost
(this.context is an Instance of ApplicationCall)
How can i get the real ip an not something like "********.dip0.t-ipconnect.de"
You can also get a remote host from the request's origin: call.request.origin.remoteHost but it returns IP address in not every case too.
I've created an issue in Ktor's bug tracker to address this problem.
Related
I have found that resolution of a hostname that does NOT exist always returns an address belonging to "akamaitechnologies.com" (e.g. 23.221.222.250). It does work correctly for hosts that do exist.
Code:
InetAddress addr = InetAddress.getByName( "NON-EXISTING.com" );
The documentation for InetAddress or a Google search provide little help. It is claimed that an UnknownHostException should occur but that does not happen for me.
Why is this happening?
This is not an Android/Java defect. It turns out it was a DNS issue. Namely, my AT&T phone uses AT&T's default DNS server (sbcglobal.net). This P.O.S. server returns a valid IP address even for non-existent domains. After I changed to "dns.google" (8.8.8.8), everything worked as expected.
This DNS spoofing is a Bad Thing because many apps depened on a Unknown-Host-Exception to detect an incorrectly entered domain, e.g. in an email address.
I am deplyong a web application in the Internet and I am checking whether the user's login is valid by checking its client IP address (e.g. 192.168.2.XXX). Actually, I have found a working code (below). This code was completely working before, but after some time, its output is not the same anymore. Now, this code only gives me 1 IP address which is the server's IP address. What is wrong with my code? How can I get the client's static IP address rather than the server's IP address? I have also tried other solutions such as getRemoteAddr() and request.getHeader("PROXY-CLIENT-IP") but it is not working.
Java:
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if(ipAddress == null)
ipAddress = InetAddress.getLocalHost().getHostAddress();
Your are mixing two levels of abstractions and that is rarely a good thing.
The header X-FORWARDED_FOR is inserted by a load balancer or proxy. If the client reaches the server directly, then this header isn't present and you are executing this code InetAddress.getLocalHost().getHostAddress();. Which does exactly what you say: It is retrieving the IP address of the host where this piece of code is running, i.e. the web server.
See also here: Getting the client IP address: REMOTE_ADDR, HTTP_X_FORWARDED_FOR, what else could be useful?
I have an rmi server on a box with two public interfaces. When a client connects, it always returns the wrong ip address in the UnicastServerRef2 [liveRef: [endpoint:[192.x.x.x:xxxx .... The connection from the client goes to the other interface with ip 10.x.x.x. Does anybody know how to solve this? I do not want to specify the ip when binding the stub. It works then, but I would like it to listen on all interfaces (0.0.0.0).
If I specify java.rmi.server.hostname=myhostname and use a RMIServerSocketFactory to create a ServerSocket[addr=myhostname/10.x.x.x,localport=xxxx], it still returns the 192.x.x.x adress to the client as remote endpoint. Weird enough I have two UnicastRemoteObjects objects on diffrerent ports and one of them returns the right address, the other not.
Any Ideas how to make it to return the endpoint with the ip of the interface the connection was made to?
That's what the java.rmi.server.hostname property is for. Set it at the exporting JVM to whatever IP address you want the clients to use to connect to it.
On a server of our private network we have an HttpServlet which is contacted by a PC of the same network.
We need to know the hostname of the client which contacts the server. To do this we call the
getRemoteHost method of the HttpServletRequest.
Some times this method returns the PC name of the client (wanted behavior) and some other the method returns the IP address. (same client, same server, same private network)
The API says:
java.lang.String getRemoteHost()
Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST
Returns:
a String containing the fully qualified name of the client
I see that for HTTP servlet that value is the same of the CGI variable REMOTE_HOST. What does it mean? Is it up to the server to decide to resolve the address or not? Is there a way to force this behavior?
In Tomcat, for example, the connector has a setting "enableLookups" which is disabled by default for performance reasons. See http://tomcat.apache.org/tomcat-7.0-doc/config/http.html
Other containers may have different methods of doing the same thing.
I'm programming a simple web browser depending on NanoHTTPD project and it's required to get number of visitors using the IP address.
Are there any ways to get the client IP using NanoHTTPD?
In NanoHTTPD.java, find the private class HTTPSession object.
Inside this is public void run(). Find the following line and add the second line after it.
decodeHeader(hin, pre, parms, header);
header.put("IPAddress", mySocket.getInetAddress().getHostAddress());
Now inside your serve function, you can just reference the IPAddress header to get the client's ip address.
I know the answer is probably too late to help you, but hopefully it'll help others searching for the same thing.
I found in the latest master branch, you can get the client ip address by header "http-client-ip" in the IHTTPSession session object.