Dzwebs.Net

撰写电脑技术杂文十余年

用ASP.Net获取客户端网卡的MAC

Admin | 2007-11-12 19:21:34 | 被阅次数 | 7101

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

此方法可实现客户IP与服务器绑定,增加权限控制:

//谨慎使用,

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 "";
}
}
}
}


该杂文来自: 网站开发杂文

上一篇:打开网站浏览页面出现乱码的解决方案

下一篇:NET操作IIS(添加虚拟目录、更改虚拟目录属性、删

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计