您的位置:首页 > 其它

获得用户(客户端)的MAC地址

2005-08-18 15:42 190 查看
ASP页面,能在windows2000上正常使用xp不能使用window2003未测试,不清楚
<%@ LANGUAGE="VBSCRIPT"%>
<%
strIP = Request.ServerVariables("REMOTE_ADDR")
strMac = GetMACAddress(strIP)
strHost = Request.ServerVariables("REMOTE_HOST")
Session("mac")=strMac
Function GetMACAddress(strIP)
Set net = Server.CreateObject("wscript.network")
Set sh = Server.CreateObject("wscript.shell")
sh.run "%comspec% /c nbtstat -A " & strIP & "> c:/" & strIP & ".txt ",0,true
Set sh = nothing
Set fso = createobject("scripting.filesystemobject")
Set ts = fso.opentextfile("c:/" & strIP & ".txt")
macaddress = null
Do While Not ts.AtEndOfStream
data = ucase(trim(ts.readline))
If instr(data,"MAC ADDRESS") Then
macaddress = trim(split(data,"=")(1))
Exit Do
End If
loop
ts.close
Set ts = nothing
fso.deletefile "c:/" & strIP & ".txt"
Set fso = nothing
GetMACAddress = macaddress
End Function
%>
<HTML>
<HEAD>
<TITLE>GetMac</TITLE>
</HEAD>
<BODY>
<%Response.Redirect("NetStart.aspx?mac=" & strMac)%>
</BODY>
</HTML>
ASP.NET程序获得客户端的MAC地址
private string ReadMac()
{
string rInfo;
try
{
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("nbtstat.exe");
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcess.StartInfo = myProcessStartInfo;
myProcessStartInfo.Arguments = @"-A "+this.Request.UserHostAddress;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
rInfo = myStreamReader.ReadToEnd();
myProcess.Close();
int local=rInfo.LastIndexOf("MAC Address");//+14
return rInfo.Substring(local+14,17);
}
catch(Exception ex)
{
return ex.Message;
}
}
在widnow2000和2003上经过测试可以使用,但在XP上还是不能使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: