在DLL中获取客户端的IP和URL
2010-10-26 08:05:37 来源:WEB开发网核心提示:以下是可在DLL层调用并获取客户端发起的URL、IP、MAC等方法using System;using System.Collections.Generic;using System.Net;using System.Web;namespace FreeShadow{ /// <summary>
以下是可在DLL层调用并获取客户端发起的URL、IP、MAC等方法
using System;using System.Collections.Generic;using System.Net;using System.Web;namespace FreeShadow{ /// <summary> /// 创建人:陈泽湖 /// 创建日期:2010-04-14 /// 功能说明:在DLL里面获取IP和URL /// </summary> public class IPAndUrlHelper { /// <summary> /// 获取主机IP /// </summary> /// <returns></returns> public static string GetHostIP() { string hostIp = string.Empty; try { System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList; foreach (IPAddress ip in addressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { hostIp = ip.ToString(); break; } } return hostIp; } catch (Exception) { return hostIp; } } /// <summary> /// 获取客户端IP /// </summary> /// <returns></returns> public static string GetClientIP() { try { string result = string.Empty; result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(result)) { result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (string.IsNullOrEmpty(result)) { result = HttpContext.Current.Request.UserHostAddress; } return result; } catch { return "无法解析IP"; } } /// <summary> /// 获取服务器IP、Mac地址 /// </summary> /// <returns></returns> public static List<string> GetHostIPAndMac() { try { List<string> list = new List<string>(); System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList; if (addressList.Length > 1) { list.Add(addressList[0].ToString()); list.Add(addressList[1].ToString()); } else { list.Add(addressList[0].ToString()); list.Add("没有可用的连接"); } return list; } catch (Exception) { return null; } } /// <summary> /// 获取库户端请求的Url /// </summary> /// <returns></returns> public static string GetClientUrl() { if(HttpContext.Current == null) { return "无法获取,该日志不是来源于Web"; } try { string result = HttpContext.Current.Request.Url.ToString(); if (string.IsNullOrEmpty(result)) { result = HttpContext.Current.Request.ServerVariables["Path_Info"]; } if (string.IsNullOrEmpty(result)) { result = HttpContext.Current.Request.UserHostAddress; } return result; } catch (Exception) { return "获取失败"; } } }}
- ››获取Android手机型号,系统版本,App版本号等信息
- ››获取Windows xp系统高权限无需注销用户
- ››URL Rewrite实现jsp网站伪静态
- ››获取checkedListBox 选中的项并且移动
- ››iphone图片拉伸的几种方法
- ››iphone正则表达式的简单使用
- ››获取ios手机的mac地址的函数
- ››iPhone开发Unresolved Symbols CAKeyframeAnimati...
- ››IPhone开发-“此证书是由未知颁发机构签名”解决方...
- ››IPhone开发-整合私钥和证书,生成.p12文件
- ››iPhone应用开发-UIPickerView选取器详解
- ››Url传参数被IE截断的解决方案
更多精彩
赞助商链接