i trying develop java web application (servlet) need clients ip address.
please not considers duplicate question because tried possible answers available in stackoverflow.
following code far:
1)
string ipaddress = request.getremoteaddr();
in case of tome 'default gateway adress'(147.120.1.5). not machine ip address(174.120.100.17).
2)
string ipaddress = request.getheader("x-forwarded-for"); if (ipaddress == null) { ipaddress = request.getremoteaddr(); }
in case of tome 'default gateway adress'(147.120.1.5). not machine ip address(174.120.100.17).
3)
inetaddress ip=inetaddress.getlocalhost(); system.out.println(ip.gethostaddress());
in case got server ip address(147.120.20.1).
my ip address in 147.120.100.17.now don't know how real client ip address. please make answer.
thank much.
try one,
string ipaddress = request.getheader("x-forwarded-for"); if (ipaddress == null) { ipaddress = request.getremoteaddr(); }
reference : http://www.mkyong.com/java/how-to-get-client-ip-address-in-java/