[英]How to read client's machine IPV4 address?
How can I read client's machine IP address from browser?如何从浏览器读取客户端的机器 IP 地址? Specially I need to do it for Internet Explorer as we're running our application for intranet.
特别是我需要为 Internet Explorer 执行此操作,因为我们正在为 Intranet 运行我们的应用程序。 I can get machine name using below code -
我可以使用以下代码获取机器名称 -
var network = new ActiveXObject('WScript.Network');
console.log(network.computerName);
Any solution/idea is much appreciated.任何解决方案/想法都非常感谢。 I am fine with applet/any server side coding.
我对小程序/任何服务器端编码都满意。 Thanks.
谢谢。
Any online service can be used such as this freegeoip.net :可以使用任何在线服务,例如这个freegeoip.net :
$.ajax({ url: '//freegeoip.net/json/', datatype: 'json', method: 'get', success: function(data) { $('pre').html("IP Addr::::" + data.ip); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <pre></pre>
One should use this if client is behind a proxy or firewall如果客户端位于代理或防火墙后面,则应使用此功能
request.getHeader("X-FORWARDED-FOR")
If Client is not using proxy or is not behind any firewall than如果客户端未使用代理或不在任何防火墙之后
request.getRemoteAddr();
should work fine SO finally summing up the whole code should be应该可以正常工作所以最后总结整个代码应该是
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if(ipAddress == null)
{
ipAddress = request.getRemoteAddr();
}
System.out.println("ipAddress:"+ipAddress);
You should checkout these links jsp get ip address http://www.coderanch.com/t/293684/JSP/java/client-IP-address-Domain-Java您应该检查这些链接jsp 获取 ip 地址http://www.coderanch.com/t/293684/JSP/java/client-IP-address-Domain-Java
i dont know if you could do that using ActiveXObject, but if you could include server side?我不知道您是否可以使用 ActiveXObject 来做到这一点,但是您是否可以包括服务器端? with php you could achieved it using
使用 php 你可以实现它
$ip=$_SERVER['REMOTE_ADDR'];
or java/jsp using或 java/jsp 使用
<%=request.getRemoteAddr()%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.