C #. Net obtain network adapter information and path information

Source: Internet
Author: User

C #. Net get network adapter Information

1: networkinterface class:

This class is located in the system. net. networkinformation namespace

This class can easily detect how many NICs (network adapters), Nic information, and which network connections are available on the local machine.

2: common methods and attributes:

Using system. net. networkinformation; namespace consoleapplication1 {class program {static void main (string [] ARGs) {networkinterface [] adapters = networkinterface. getallnetworkinterfaces (); // obtain the network interface object console on the local computer. writeline ("Number of adapters:" + adapters. length); console. writeline (); foreach (networkinterface adapter in adapters) {console. writeline ("Description:" + adapter. description); console. writeline ("identifier:" + Dapter. ID); console. writeline ("name:" + adapter. name); console. writeline ("type:" + adapter. networkinterfacetype); console. writeline ("Speed:" + adapter. speed * 0.001*0.001 + "M"); console. writeline ("Operation Status:" + adapter. operationalstatus); console. writeline ("MAC address:" + adapter. getphysicaladdress (); // format the MAC address physicaladdress Pa = adapter. getphysicaladdress (); // obtain the media access (MAC) Address of the adapter. byte [] bytes = pa. getaddr Essbytes (); // return the address of the current instance stringbuilder sb = new stringbuilder (); For (INT I = 0; I <bytes. length; I ++) {sb. append (Bytes [I]. tostring ("X2"); // format if (I! = Bytes. length-1) {sb. append ("-") ;}} console. writeline ("MAC address:" + Sb); console. writeline ();} console. readkey ();}}}

C #. net

 
Application. startuppath // get started ApplicationProgramThe path of the executable file, excluding the name of the executable file. Application. executablepath // obtain the path of the executable file that started the application, including the name of the executable file. Appdomain. currentdomain. basedirectory // obtain the base Directory, which is used by the Assembly conflict resolution program to detect the assembly. Thread. getdomain (). basedirectory // obtain the base Directory, which is used by the Assembly conflict resolution program to detect the assembly. Environment. currentdirectory // obtain or set the fully qualified path of the current working directory. Directory. getcurrentdirectory () // obtain the current working directory of the application. Assembly. getexecutingassembly (). Location // gets the path or UNC location of the loaded file that contains the list.

Get through the request property:

 
// Obtain the physical file system path of the root directory of the currently running server application. Request. physicalapplicationpath; // E: \ solution \ project \ // obtain the physical file system path corresponding to the requested URL. Request. physicalpath; // E: \ solution \ project \ ZZ. aspx

Obtain the virtual path and URL Information: (URL:Http: // localhost/ASPnet/ZZ. aspx/info? Name = wk)

// Obtain ASP on the server. NET application root path:/request. applicationpath; // ASPnet // obtain the virtual path of the application root and use the waveform character (~) for the application root (~) Make the path a relative path. Request. apprelativecurrentexecutionfilepath ;//~ /ZZ. aspx // obtain the virtual path request of the current request. currentexecutionfilepath; // ASPnet/ZZ. aspxrequest. filepath; // ASPnet/ZZ. aspx // obtain the object name extension specified in the currentexecutionfilepath attribute. Request. currentexecutionfilepathextension ;//. aspx // obtain the virtual path of the current request (including the attachment path information) request. path; // ASPnet/ZZ. aspx/INFO // obtain the additional path information of the resource with the URL extension. Request. pathinfo; // info // obtain information about the URL of the current request. Request. url; // http: // localhost/ASPnet/ZZ. aspx/INF? Name = wk // obtain the original URLRequest. rawurl of the current request; // ASPnet/ZZ. aspx/INF? Name = wk // obtain the URL Information about the client's last request. The request is linked to the current URL. Request. urlreferrer; // system. Uri

From http://www.cnblogs.com/zhanqi/

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.