在.NET中獲取一台電腦名,IP地址及當前用戶名是非常簡單,以下是我常用的幾種方法,如果大家還有其它好的方法,可以回復一起整理: 1. 在ASP.NET中專用屬性: 獲取服務器電腦名:Page.Server.ManchineName 獲取用戶信息:Page.User 獲取客戶端電腦名:Page.Request.UserHostName 獲取客戶端電腦IP:Page.Request.UserHostAddress 2. 在網絡編程中的通用方法: 獲取當前電腦名:static System.Net.Dns.GetHostName() 根據電腦名取出全部IP地址:static System.Net.Dns.Resolve(電腦名).AddressList 也可根據IP地址取出電腦名:static System.Net.Dns.Resolve(IP地址).HostName 3. 系統環境類的通用屬性: 當前電腦名:static System.Environment.MachineName 當前電腦所屬網域:static System.Environment.UserDomainName 當前電腦用戶:static System.Environment.UserName Request.UserHostAddress string IP = (Request.ServerVariables["HTTP_VIA"]!=null)?Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString():Request.ServerVariables["REMOTE_ADDR"].ToString(); string ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress; 先引用命名空間:using System.Net; 得到客戶端IP地址:Request.ServerVariables["REMOTE_ADDR"]或Rqurest.UserHostAddress(); 得到本機IP地址:Request.ServerVariables["local_addr"]或addr = new System.Net.IPAddress ( Dns.GetHostByName ( Dns.GetHostName ( ) ) .AddressList [0].Address ) ; HttpBrowserCapabilities bc= Request.Browser; Label3.Text=bc.Browser+" "+bc.Version;//得到瀏覽器版本 Label2.Text=bc.Platform;//得到操作系統 hostname=Dns.GetHostName(); IPHostEntry jj=Dns.GetHostByName(hostname);//得到IP //IPAddress ip=Dns.Resolve(hostname); Label1.Text=jj.AddressList[0].ToString();