Copy codeThe Code is as follows:
Using System. Text. RegularExpressions;
Using System. Diagnostics;
Public class test
{
Public test
{}
Public static string GetCustomerMac (string IP) // para IP is the clients IP
{
String dirResults = "";
ProcessStartInfo psi = new ProcessStartInfo ();
Process proc = new Process ();
Psi. FileName = "nbtstat ";
Psi. RedirectStandardInput = false;
Psi. RedirectStandardOutput = true;
Psi. Arguments = "-A" + IP;
Psi. UseShellExecute = false;
Proc = Process. Start (psi );
DirResults = proc. StandardOutput. ReadToEnd ();
Proc. WaitForExit ();
DirResults = dirResults. Replace ("","");
Regex reg = new Regex ("Mac [] {0,} Address [] {0,} = [] {0 ,}(? <Key> ((.)*?)) _ MAC ", RegexOptions. IgnoreCase | RegexOptions. Compiled );
Match mc = reg. Match (dirResults + "_ MAC ");
If (mc. Success)
{
Return mc. Groups ["key"]. Value;
}
Else
{
Reg = new Regex ("Host not found", RegexOptions. IgnoreCase | RegexOptions. Compiled );
Mc = reg. Match (dirResults );
If (mc. Success)
{
Return "Host not found! ";
}
Else
{
Return "";
}
}
}
}