In. net, obtain the server computer name, user information, client computer name, and client computer ip address.
1 . Private 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:
Obtain 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 retrieve the computer name based on the IP Address: Static System. net. DNS. Resolve (IP address). hostname
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
For example:
Using System. net;
Private Void Buttonip_click ( Object Sender, system. eventargs E)
{
System. net. IPaddress [] Addresslist = DNS. gethostbyname (DNS. gethostname (). Addresslist;
If (Addresslist. Length > 1 )
{
Textlip. Text=Addresslist [0]. Tostring ();
Textsip. Text=Addresslist [1]. Tostring ();
}
Else
{
Textlip. Text=Addresslist [0]. Tostring ();
Textsip. Text= "No available connections";
}
}