Here is an example of the code that the MAC requests in an active connection, this is a console application, you do not need to do this with a Windows form ...
public class TestARP
{
private StringBuilder sbRedirectedOutput = new StringBuilder ();
public string OutputData
{
get {return this.sbRedirectedOutput.ToString (); }
}
// Asynchronous!
public void Run ()
{
System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo ();
ps.FileName = "arp";
ps.ErrorDialog = false;
ps.Arguments = "-a";
ps.CreateNoWindow = true; // comment this out
ps.UseShellExecute = false; // true
ps.RedirectStandardOutput = true; // false
ps.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; // comment this out
using (System.Diagnostics.Process proc = new System.Diagnostics.Process ())
{
proc.StartInfo = ps;
proc.Exited + = new EventHandler (proc_Exited);
proc.OutputDataReceived + = new System.Diagnostics.DataReceivedEventHandler (proc_OutputDataReceived);
proc.Start ();
proc.WaitForExit ();
proc.BeginOutputReadLine (); // Comment this out
}
}
void proc_Exited (object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine ("proc_Exited: Process Ended");
}
void proc_OutputDataReceived (object sender, System.Diagnostics.DataReceivedEventArgs e)
{
if (e.Data! = null) this.sbRedirectedOutput.Append (e.Data + Environment.NewLine);
}
}
Now consider the Run method, which is in asynchronous mode, and runs as a single console window - in fact, this is a normal console application without a pop-up window, pay attention to comments, if you had to change these lines, it becomes a synchronous process, cost very fast , you will notice that this console will create another window with the output of the arp command. Since it is in asynchronous mode, the output is redirected to the event handler, which fills the data in the StringBuilder instance for further processing ...
Hope this helps, Regards, Tom.
source share