Microsoft Study Bible

September 18, 2009

How to Attain NIC MAC address with C# code??

Filed under: Developer tools and applications — Tags: , — Jackson @ 5:20 am

It’s known to everyone that the NIC MAC address could be gotten, when we input the command “ipconfig /all” in DOS and run it.

However, what about the detailed codes?? And how to intercept the output stream by running a dos command in C#?

The detailed codes will be shown below:

C# code

 tbResult.Text = “”;

 ProcessStartInfo start = new ProcessStartInfo(”Ping.exe”);

 start.Arguments = txtCommand.Text;// Setting Command Parameters

 start.CreateNoWindow = true;//no show DOS command prompt window

 start.RedirectStandardOutput = true;

 start.RedirectStandardInput = true;

 start.UseShellExecute = false;

 Process p=Process.Start(start);

 StreamReader reader = p.StandardOutput;//intercept the output stream

 string line = reader.ReadLine();//read one line every time

 while (!reader.EndOfStream)

 {

 tbResult.AppendText(line+” “);

 line = reader.ReadLine();

 }

 p.WaitForExit();//exit when the programs finish executing

 p.Close();//close process

 reader.Close();//close the stream

 

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Close
E-mail It