jquery获取外部IP,不使用任何外部链接 [英] jquery get external IP, without using any external links

查看:90
本文介绍了jquery获取外部IP,不使用任何外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取客户端IP,下面是工作的jquery代码

i wanted to get the client IP, below is the working jquery code

function getIP() {
        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){
       alert(response.ip);
   }





问题是 http://jsonip.appspot.com/?callback=DisplayIP [ ^ ],有时网站关闭,例如现在,它说它超过了配额。所以我想知道有没有可能我可以检查客户端IP而不使用任何外包?



problem is the http://jsonip.appspot.com/?callback=DisplayIP[^] , sometime the website is down, for example now, it said it's over quota. so i wonder is there any possible i can check the client IP without using any outsource?

推荐答案

嘿读者,

使用此代码C#,我认为它对你有帮助。

Hey Reader,
Use this code of C#, I think it might be helpful to you.
Dim strIpAddress As String = GetIPAddress()
        Dim strgetserverlocation As String = GetServerInfo()
        Dim Datetime__1 As String = Convert.ToString(DateTime.Now)



公共函数GetIPAddress()As String

尝试

Dim ipAdd As String

Dim currentRequest As HttpRequest = HttpContext.Current。请求

ipAdd = currentRequest.ServerV ariables(HTTP_X_FORWARDED_FOR)



如果ipAdd是Nothing OrElse ipAdd.ToLower()=unknown那么

ipAdd = currentRequest.ServerVariables (REMOTE_ADDR)

结束如果



返回ipAdd

Catch ex As Exception

抛出ex

结束尝试

结束函数

公共函数GetServerInfo()As String

试试

Dim Sinfo As String

Dim currentRequest As HttpRequest = HttpContext.Current.Request

Sinfo = currentRequest.ServerVariables(HTTP_X_FORWARDED_FOR)



如果Sinfo什么都没有OrElse Sinfo.ToLower()=unknown那么

Sinfo = currentRequest.ServerVariables(REMOTE_ADDR)

Sinfo + =/+ currentRequest.ServerVariables(LOGON_USER)

结束如果

Dim computerinfo As String()= Sinfo.Split(/c)



返回computerinfo(1)

Catch ex As Exception

抛出ex

结束尝试

结束功能


Public Function GetIPAddress() As String
Try
Dim ipAdd As String
Dim currentRequest As HttpRequest = HttpContext.Current.Request
ipAdd = currentRequest.ServerVariables("HTTP_X_FORWARDED_FOR")

If ipAdd Is Nothing OrElse ipAdd.ToLower() = "unknown" Then
ipAdd = currentRequest.ServerVariables("REMOTE_ADDR")
End If

Return ipAdd
Catch ex As Exception
Throw ex
End Try
End Function
Public Function GetServerInfo() As String
Try
Dim Sinfo As String
Dim currentRequest As HttpRequest = HttpContext.Current.Request
Sinfo = currentRequest.ServerVariables("HTTP_X_FORWARDED_FOR")

If Sinfo Is Nothing OrElse Sinfo.ToLower() = "unknown" Then
Sinfo = currentRequest.ServerVariables("REMOTE_ADDR")
Sinfo += "/" + currentRequest.ServerVariables("LOGON_USER")
End If
Dim computerinfo As String() = Sinfo.Split("/"c)

Return computerinfo(1)
Catch ex As Exception
Throw ex
End Try
End Function


这代码适用于在线和Lan。因为这个网站现在正在运行代码。!!
This code is for both online and Lan also.! because this now running code on website.!!


这篇关于jquery获取外部IP,不使用任何外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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