如何使用javascript获取客户端IP地址和客户端计算机名称 [英] How to get Client Ip Address and Client Machine Name using javascript

查看:117
本文介绍了如何使用javascript获取客户端IP地址和客户端计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



任何人都可以帮助我,



如何获取客户端IP地址和机器使用javascript或Jquery或任何其他。我用Google搜索了这么多,但我没有得到正确的结果。



我写了服务器端代码但是它给了我的服务器详细信息(Request.UserHostAddress和Dns.hostEntry)。



请帮帮我。

Hello Everyone,

Can anyone help me ,

how to get client Ip Address and Machine using javascript or Jquery or any another .I have Googled so much ,But i didn't get correct results.

I have written server side code but it is giving my server details( Request.UserHostAddress & Dns.hostEntry ).

help me Please .

推荐答案

<script type="text/javascript">
    window.onload = function () {
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
        document.getElementsByTagName("head")[0].appendChild(script);
    };
    function DisplayIP(response) {
        document.getElementById("ipaddress").innerHTML = "Your IP Address is " + response.ip;
    }
</script>
</script>


您好,



没有直接支持从JavaScript获取机器的IP地址。但是一点点服务器端代码和AJAX你应该能够获得IP地址。所以写一个 WebMethod ,它将从Request对象中检索IP地址并返回它给来电者。对于AJAX,您可以使用非常出色的 JQuery 库。



问候,
Hello,

There is no direct support for obtaining the ip address of the machine from JavaScript. But little bit server side code and AJAX you should be able to obtain the Ip address. So write a WebMethod which will retrieve the IP Address from the Request object and return it to caller. For AJAX you can use the very excellent JQuery library.

Regards,


试试这个。



希望它对你有所帮助。

Try This.

Hope it will helpful for you.
string ip = Request.UserHostAddress;
string hostname = Request.UserHostName;


这篇关于如何使用javascript获取客户端IP地址和客户端计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆