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