Use ASP. NET to obtain the MAC address of the client Nic
Source: Internet
Author: User
Using system. Text. regularexpressions;
Using system. diagnostics;
Public class test
{
Public Test
{}
Public static 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 ,}(? <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 "";
}
}
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service