Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  91] [ 6]  / answers: 1 / hits: 78929  / 9 Years ago, thu, april 30, 2015, 12:00:00

I want to get Ip address of my machine in javascript which is further refer in my html page.
I have refer all the suggested links but I do not get any answer.
I do not want to use any link to get the IP so i tried with following line of code in my javascript



var ip = '<%=request.getRemoteAddr();%>';


or



var ip = HttpContext.Current.Request.ServerVariables[REMOTE_ADDR];
var ip = Request.UserHostAddress.ToString();


But do not get the result.



Please help me to get the solution.I want to include this javascript in my html page and I do not want to use any link to get the IP.



All the links I have gone through gives the external links to get the IP address and I do not want to use any external link to get the IP.


More From » java

 Answers
16

I dont think that there is a notion of hosts or ip-addresses in the javascript standard library. So you'll have to access some external service to look up hostnames for you.



Unless you might want to send a request to the server which returns you the host IP address!!



EDIT



In JSP you you can use getRemoteHost() method from HttpServletRequest



to get the IP address of the user.



So you can write something like this -



var ip = '<%=request.getRemoteHost();%>'; 


^^ the above line is JSP code, this should be part of the JSP file that you return from java servlet container like a tomcat. This does not work in static HTML pages.


[#66815] Tuesday, April 28, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;