日期:2014-05-20  浏览次数:21203 次

C#跨网段获取MAC地址
记忆中好像有这样的一个个性签名,里面写到,
欢迎你来是XX省xx市的朋友
你的Ip是:xxx.xxx.xxx.xxx
你的MAC地址是:xx-xx-xx-xx-xx-xx 这样的地址,
当时还不知道是怎么回事情,
现在突然想做这样一个功能,但是苦寻千里,挖心费神,
得来的不过是只能在局域网中取得访问者MAC的东西,
唯请能者指点一二,
难道真的没办法吗
都说,可以用插件,但是插件叫什么,望能告之,
小女子将感激不尽。

------解决方案--------------------
HTML code

<-- 
这是我之前做的..可以获取到..不过要设置浏览器的允许Activex插件运行 
-->
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head > 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
    <object id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" viewastext> </object> 
    <object id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"> </object> 
    <script type="text/jscript" event="OnObjectReady(objObject,objAsyncContext)" for="foo" >  
    if(objObject.IPEnabled !=null &&objObject.IPEnabled !="undefined"&&objObject.IPEnabled==true)  
    {  
      if(objObject.MACAddress!= null&&objObject.MACAddress!="undefined")  
        MACAddr  = objObject.MACAddress;  
    }  
    </script> 
    <script type="text/jscript">  
      var  service = locator.ConnectServer();  
      var  MACAddr  ;  
      service.Security_.ImpersonationLevel=3;  
      service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');  
    </script> 

    <script type="text/jscript" event="OnCompleted(hResult,pErrorObject,pAsyncContext)" for="foo" > 
        document.form1.TextBox1.value=unescape(MACAddr); 
        document.form1.submit();
    </script> 

    <title>无标题页 </title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <%aaaa(); %>
        <div>
            获取网卡地址前,请进入Internet属性设置->安全>自定义级别->"对没有标记为安全的ActiveX控件进行初始化和脚本运行"->点选"启用" 

        </div>
        <div> 
            您目前的网卡地址是:<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> 
            <asp:Button ID="button1" runat="server" OnClick="button1_Click1" />
        </div> 
    </form> 
</body> 
</html> 
<script runat="server">

    protected void aaaa()
    {
        // http://192.168.0.144/Proscenium/PublicFile/dd.aspx
        if (!string.IsNullOrEmpty(this.TextBox1.Text))
        {
            Session["objObject.MACAddress"] = this.TextBox1.Text;
        }
        if (Session["objObject.MACAddress"] != null)
        {
            Response.Redirect("help000.html");
            return;
        }
        
       
    }

    protected void button1_Click(object sender, EventArgs e)
    {
        aaaa();
    }

    protected void button1_Click1(object sender, EventArgs e)
    {
        aaaa();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
</script>