using System;
using System.Web;
namespace KkSys.Web
{
public class PageInfor
{
///
/// 获取页面名(包括扩展名)
///
public static string PageName
{
get
{
return HttpContext.Current.Request.Url.AbsolutePath.Substring(HttpContext.Current.Request.Url.AbsolutePath.LastIndexOf('/') + 1);
}
}
///
/// 用户IP
///
public static string UserIP
{
get
{
string user_IP = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
user_IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
user_IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
return user_IP;
}
}
///
/// web服务器的名称和版本
///
public static string WebName
{
get
{
return HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
}
}
///
/// 协议的名称和版本
///
public static string PROTOCOL
{
get
{
return HttpContext.Current.Request.ServerVariables["SERVER_PROTOCOL"];
}
}
///
/// 服务器处理请求的端口
///
public static string PORT
{
get
{
return HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
}
}
///
/// 获取跟目录路径
///
public static string GetServerPath
{
get
{
return HttpContext.Current.Server.MapPath("~");
}
}
///
/// 获取当前路径
///
public static string GetCurrentPath
{
get
{
return HttpContext.Current.Server.MapPath("");
}
}
///
/// 服务器的主机名
///
public static string ServerName
{
get
{
return HttpContext.Current.Request.ServerVariables["LOGON_USER"];
}
}
///
/// 服务器类型
///
public static string ServerIp
{
get
{
return HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"];
}
}
}
}
巧了,以前在公司主管还真让写过一个。using System.IO;using System.Net;using System.Text;using System.Text.RegularExpressions; static string GetPage(string url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); try { using (HttpWebResponse res = (HttpWebResponse)req.GetResponse()) { using (StreamReader sr = new StreamReader(res.GetResponseStream())) { return sr.ReadToEnd(); } } } catch (System.Exception e) { return e.Message; } finally { req.Abort(); } } // 通过外部网站得到本机的外部IP static string GetOuterIP() { string patt = @"IP: \[(?[0-9\.]*)\]"; string url = " http://www.skyiv.com/info"; return Regex.Match(GetPage(url), patt).Groups["IP"].Value; }看看好用不
string IP=Request.ServerVariables["REMOTE_ADDR"];