Get client network card code

xiaoxiao2021-03-17  179

public string GetCustomerMac (string IP) // para IP is the client's 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 ("/ r", ""). Replace ("/ n", ""). Replace ("/ t", "");

Regex reg = new regex ("Mac [] {0,} address [] {0,} = [] {0,} (? ((.))) __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 solid!"} Else {string matchmac = dirResults.Substring (DirResults.Length-17, 17); return matchmac;}}}

Call method getcustomermac (192.168.0.1)

转载请注明原文地址:https://www.9cbs.com/read-129548.html

New Post(0)