C # Gets the computer name, current login username, IP address.

Source: Internet
Author: User
Get a computer name in. NET, IP address and current username is very simple, the following are my common methods, if you have other good methods, you can reply together:
1. Special properties in asp.net:
Get Server computer name: Page.Server.ManchineName
Get user information: Page.User
Get client computer name: Page.Request.UserHostName
Get client computer IP:Page.Request.UserHostAddress
2. Common methods in Network programming:
Get current computer name: Static System.Net.Dns.GetHostName ()
Remove all IP addresses according to computer name: Static System.Net.Dns.Resolve (computer name). AddressList
The computer name can also be removed according to the IP address: static System.Net.Dns.Resolve (IP address). HostName
3. Common properties of System environment class:
Current computer name: Static System.Environment.MachineName
Current computer-owned domain: static System.Environment.UserDomainName
Current computer User: Static System.Environment.UserName

Examples to illustrate:

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 connections available";
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.