会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
BB.NET
每天一小步
博客园
首页
新随笔
联系
订阅
管理
获取客户端的ip地址
//
获取客户端的ip地址
public
string
GetClientIP()
{
string
result
=
HttpContext.Current.Request.ServerVariables[
"
HTTP_X_FORWARDED_FOR
"
];
if
(
null
==
result
||
result
==
String.Empty)
{
result
=
HttpContext.Current.Request.ServerVariables[
"
REMOTE_ADDR
"
];
}
if
(
null
==
result
||
result
==
String.Empty)
{
result
=
HttpContext.Current.Request.UserHostAddress;
}
return
result;
}
//
将IP 地址转化为数字
public
long
IPtoNum(
string
Ip)
{
string
[] stringip
=
new
string
[
4
];
stringip
=
Ip.Split(
'
.
'
);
long
ipnum
=
Convert.ToInt64((stringip[
0
]))
*
16777216
+
Convert.ToInt64(stringip[
1
])
*
65536
+
Convert.ToInt64(stringip[
2
])
*
256
+
Convert.ToInt64(stringip[
3
]);
return
ipnum;
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
Response.Write(GetIP());
}
posted @
2008-03-01 09:30
melody&bobo
阅读(
186
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告