在.NET--C#编程时,怎样获得远程客户端物理MAC地址,请指教,谢谢!

解决方案 »

  1.   

    我还想用一个html页面得到客户端的文件呢!晕
      

  2.   

    除非用ActiveX控件了,否则不太可能实现了。
    因为这样太危险了,万一有人想在客户端执行format c:之类的...
      

  3.   

    declare @ip varchar(15),@sql varchar(1000)--得到ip地址
    create table #ip(a varchar(200))
    set @sql='ping '+host_name()+' -a -n 1 -l 1'
    insert into #ip exec master..xp_cmdshell @sqlselect @ip=left(a,patindex('%:%',a)-1) from(
    select a=substring(a,patindex('Ping statistics for %:%',a)+20,20)
    from #ip where a like 'Ping statistics for %:%') a--显示结果
    select 用户计算机名=host_name(),ip地址=@ipdrop table #ip
    =============================================================================================create table #(txt varchar(200))
    insert # exec master..xp_cmdshell 'ipconfig /all'select * from # where ltrim(txt) like 'host name%' or ltrim(txt) like 'ip address%'drop table #--结果
    /*
    txt                                                 
    ------------------------------------------------------------
       Host Name . . . . . . . . . . . . : Lydia   IP Address. . . . . . . . . . . . : 192.168.18.188   IP Address. . . . . . . . . . . . : 192.168.18.168   IP Address. . . . . . . . . . . . : 192.168.18.18
    (所影响的行数为 4 行)
    */
      

  4.   

    using System.Runtime.InteropServices;  [DllImport("Iphlpapi.dll")] 
      private static extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); 
      [DllImport("Ws2_32.dll")] 
      private static extern Int32 inet_addr(string ip);   static private Int64 getRemoteMAC(string localIP, string remoteIP) 
      { 
       Int32 ldest= inet_addr(remoteIP);        //远程主机ip 
       Int32 lhost= inet_addr(localIP);            //本机ip    try 
       { 
        Int64 macinfo = new Int64(); 
        Int32 len = 6; 
        int res = SendARP(ldest,0, ref macinfo, ref len); 
        return macinfo; 
       } 
       catch(Exception err) 
       { 
        Console.WriteLine("Error:{0}",err.Message); 
       } 
       return 0; 
      }