返回首页
当前位置: 主页 > 网络编程 > .Net实例教程 >

利用c#获取真实IP和代理IP代码

时间:2012-01-29 23:15来源:知行网www.zhixing123.cn 编辑:麦田守望者

01.public static string GetRealIP()
02.{
03.string ip;
04.try
05.{
06.HttpRequest request = HttpContext.Current.Request;
07.
08.if (request.ServerVariables["HTTP_VIA"] != null)
09.{
10.ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
11.}
12.else
13.{
14.ip = request.UserHostAddress;
15.}
16.}
17.catch (Exception e)
18.{
19.throw e;
20.}
21.
22.return ip;
23.}
获取代理IP


view plaincopy to clipboardprint?
01.public static string GetViaIP()
02.{
03.string viaIp = null;
04.
05.try
06.{
07.HttpRequest request = HttpContext.Current.Request;
08.
09.if (request.ServerVariables["HTTP_VIA"] != null)
10.{
11.viaIp = request.UserHostAddress;
12.}
13.
14.}
15.catch (Exception e)
16.{
17.
18.throw e;
19.}
20.
21.return viaIp;

------分隔线----------------------------
标签(Tag):C# C#实例教程 c#基础教程 C#源代码 c#技巧
------分隔线----------------------------
推荐内容
猜你感兴趣