会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
我的番茄炒蛋
生活如此精彩,挑战无处不在!
导航
博客园
首页
新随笔
联系
订阅
管理
公告
用ASP.Net获取客户端网卡的MAC
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
""
;
}
}
}
}
posted on
2005-09-03 23:05
bluesky
阅读(
266
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部