PRO.Common/IP.cs
(完整代码) 1KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PRO.Common
{
/// <summary>
/// 系统公共使用部分
/// </summary>
public static class IP
{
/// <summary>
/// 获取ip地址
/// </summary>
/// <returns></returns>
public static string GetIP()
{
string ip = string.Empty;
try
{
if (System.Web.HttpContext.Current != null)
{
if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) // 服务器, using proxy
{
//得到真实的客户端地址
ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP.
}
else//如果没有使用代理服务器或者得不到客户端的ip not using proxy or can't get the Client IP
{
//得到服务端的地址要判断 System.Web.HttpContext.Current 为空的情况
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
}
}
}
catch (Exception ep)
{
ip = "没有正常获取IP," + ep.Message;
}
return ip;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。