C #. NET Getting network adapter information
1:networkinterface class:
The class is located in the System.Net.NetworkInformation namespace
This class can easily detect how many network cards (network adapters), NIC information, which Internet connection is available, etc.
2: Common Methods and properties:
usingSystem.Net.NetworkInformation;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) {networkinterface[] Adapters= Networkinterface.getallnetworkinterfaces ();//gets the object for the network interface on the local computerConsole.WriteLine ("Number of adapters:"+adapters. Length); Console.WriteLine (); foreach(NetworkInterface Adapterinchadapters) {Console.WriteLine ("Description:"+adapter. Description); Console.WriteLine ("identifiers:"+adapter. 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 ()); //formatted display MAC addressPhysicaladdress PA = adapter. Getphysicaladdress ();//Get the media access (MAC) address of the adapter byte[] bytes = Pa. Getaddressbytes ();//returns the address of the current instanceStringBuilder SB =NewStringBuilder (); for(inti =0; I < bytes. Length; i++) {sb. Append (Bytes[i]. ToString ("X2"));//formatted in hexadecimal if(I! = bytes. Length-1) {sb. Append ("-"); }} Console.WriteLine ("MAC Address:"+SB); Console.WriteLine (); } console.readkey (); } }}
C #. NET Get path information
Application.startuppath//gets the path to the executable file that launched the application, not including the name of the executable file. Application.executablepath//gets the path to the executable file that launched the application, including the name of the executable file. AppDomain.CurrentDomain.BaseDirectory//gets the base directory that is used by the Assembly resolver to probe assemblies. Thread.getdomain (). BaseDirectory//gets the base directory that is used by the Assembly resolver to probe assemblies. environment.currentdirectory//Gets or sets the fully qualified path to the current working directory. directory.getcurrentdirectory ()//gets the current working directory of the application. assembly.getexecutingassembly (). Location//gets the path or UNC location of the loaded file that contains the manifest. get through the Request property://gets the physical file system path of the root directory of the server application that is currently executing. Request.physicalapplicationpath;//e:\ solution \ Project//gets the physical file system path that corresponds to the requested URL. Request.PhysicalPath;//e:\\ solution \ Project \zz\zz.aspxGet virtual path and URL information: (url:http://localhost/aspnet/zz/zz.aspx/info?name=wk)//get the virtual application root path of an ASP. NET application on the server:/Request.applicationpath;///aspnet//gets the virtual path of the application root and makes the path a relative path by using the tilde (~) notation on the application root. Request.apprelativecurrentexecutionfilepath;//~/zz/zz.aspx//gets the virtual path of the current requestRequest.currentexecutionfilepath;///aspnet/zz/zz.aspxRequest.filepath;///aspnet/zz/zz.aspx//gets the extension of the file name specified in the Currentexecutionfilepath property. Request.currentexecutionfilepathextension;//. aspx//gets the virtual path of the current request (including the Attachment path information)Request.path;///aspnet/zz/zz.aspx/info//Gets the additional path information for a resource with a URL extension. Request.pathinfo;///info//gets information about the URL of the current request. Request.url;// Http://localhost/aspnet/zz/zz.aspx/inf?name=wk //gets the original URL of the current requestRequest.rawurl;///aspnet/zz/zz.aspx/inf?name=wk//gets information about the URL of the client's last request, which is linked to the current URL. Request.urlreferrer;//System.Uri
C #. NET Get network adapter information and path information