Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

I found in the latest master branch, you can get the client ip address by header "http-client-ip" in the IHTTPSession session object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top