其实你只要搜索一下 MAC 就会查到很多以前的贴子,不用浪费这100分的:[DllImport("Iphlpapi.dll")]
private static extern int SendARP(Int32 dest,Int32 host,byte[] mac,ref Int32 length);
[DllImport("Ws2_32.dll")] 
private static extern Int32 inet_addr(string ip);
public static string GetMACByIP(string ip) 

try 

byte[] aa=new byte[6];Int32 ldest= inet_addr(ip); //目的地的ip Int64 macinfo = new Int64(); 
Int32 len = 6; 
int res = SendARP(ldest,0, aa, ref len); return BitConverter.ToString( aa, 0, 6 );;

catch(Exception err) 

throw err; 
}

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/3414/3414902.xml?temp=.9261591
      

  2.   

    public  string GetMac(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 "";
    }
    }
    }
      

  3.   

    如果要想获得远程的地址,需要用sendarp这个函数来实现。具体的代码如下:
    [DllImport("Iphlpapi.dll")]
    private  static  unsafe  extern  int  SendARP(Int32  dest,Int32  host,ref  IntPtr  mac,ref  IntPtr  length);
    [DllImport("Ws2_32.dll")]
    private  static  extern  Int32  inet_addr(string  ip);Int32  ldest=  inet_addr("157.60.68.163");//目的地的ip
    Int32  lhost=  inet_addr("157.60.68.33");//本地的iptry
    {
    Byte[]  macinfo=new  Byte[6];
    Int32  length=6;IntPtr  mac=new  IntPtr(macinfo[0]);
    IntPtr  len=new  IntPtr(6);
    int  ii=SendARP(ldest,lhost,  ref  mac,  ref  len);Console.WriteLine("Mac  Add:"+mac);
    Console.WriteLine("length:"+len);
    }
    catch(Exception  err)
    {
    Console.WriteLine(err);
    }
      

  4.   

    如果你的网络里用的不是Windows98的话完全可以用Wmi解决方案
    //新建连接
    string username="computerusername";  //远程计算机的用户名
    string userpass="computerpass";      //远程计算机的密码
    string computer="computer";          //你要访问的远程计算机名也可以是ip地址
    ConnectionOptions con=new ConnectionOptions();
    con.Username=username;
    con.Password=userpass;
    ManagementScope ms=new ManagementScope("\\\\"+computer+"\\root\\cimv2",con);
    try
    {
      ms.Connect();
    }
    catch
    {
      MessageBox.Show("远程计算机不可用");
    }
    ManagementClass mc=new ManagementClass(ms,new ManagementPath("Win32_NetworkAdapterConfiguration"),null);ManagementObjectCollection mo=mc.GetInstances();foreach(ManagementObject o in mo)
    {
      Console.WriteLine(o["MACAddress"].ToString());  //这就是你想要的
    }
      

  5.   

    using System.Management;//get the MAC addressManagementClass mc=new ManagementClass("Win32_NetworkAdapterConfiguration");ManagementObjectCollection moc=mc.GetInstances();string[] MacAddress=new string[2];int ii=0;foreach(ManagementObject mo in moc){ if((bool)mo["IPEnabled"]==true) { MacAddress[ii]=mo["MacAddress"].ToString(); ii++; }mo.Dispose();}
      

  6.   

    <%@ LANGUAGE="VBSCRIPT"%>
    <%
    strIP = Request.ServerVariables("REMOTE_ADDR")
    strMac = GetMACAddress(strIP)
    strHost = Request.ServerVariables("REMOTE_HOST")
    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 
    response.write(macaddress)
    %>