In. NET, it is very easy to get a computer name, IP address and current user name. The following are some of my frequently used methods. If you have other good methods, you can reply to them:
1. Special attributes in ASP. NET:
Get Server computer name: Page. Server. ManchineName
Get User information: Page. User
Obtain the client computer name: Page. Request. UserHostName
Obtain the Client IP Address: Page. Request. UserHostAddress
2. General methods in network programming:
Get the current computer name: static System. Net. Dns. GetHostName ()
Retrieve all IP addresses based on the computer name: static System. Net. Dns. Resolve (computer name). AddressList
You can also obtain the computer name static System. Net. Dns. Resolve (IP address). HostName Based on the IP address.
3. General attributes of the system environment:
Current computer name: static System. Environment. MachineName
Domain Name of the current computer: static System. Environment. UserDomainName
Current computer user: 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;
Reference namespace first: using System. Net;
Obtain the Client IP Address: Request. ServerVariables ["REMOTE_ADDR"] Or Rqurest. UserHostAddress ();
Obtain the local IP Address: Request. serverVariables ["local_addr"] Or addr = new System. net. IPAddress (Dns. getHostByName (Dns. getHostName ()). addressList [0]. address );
HttpBrowserCapabilities bc = Request. Browser;
Label3.Text = bc. Browser + "" + bc. Version; // obtain the Browser Version.
Label2.Text = bc. Platform; // obtain the Operating System
Hostname = Dns. GetHostName ();
IPHostEntry jj = Dns. GetHostByName (hostname); // obtain the IP address
// IPAddress ip = Dns. Resolve (hostname );
Label1.Text = jj. AddressList [0]. ToString ();