怎样获取远程主机MAC地址?给段代码看看!!!

解决方案 »

  1.   

    我也是搜索来的,没有自己编写测试过.  Delphi 6procedure TForm1.Button2Click(Sender: TObject); //发送“UDP-NetBIOS-NS”询问包
    var
    MyStream:TMemoryStream;
    t_ns:tNetBiosNS;
    i:byte;
    begin
    with t_ns do
    begin
    tID:=$0000;
    Flags:=$1000;
    Questions:=$0100;
    AnswerRRs:=$0000;
    AuthorityRRs:=$0000;
    AdditionalRRs:=$0000;
    Name[1]:=$20;
    Name[2]:=$43;
    Name[3]:=$4b;
    for i:=4 to 33 do
    Name:=$41;
    Name[34]:=$00;
    tType:=$2100;
    tClass:=$0100;
    end;
    nmudp1.LocalPort:=3000;//UDP绑定的本地主机的端口
    nmudp1.RemoteHost:=edit1.Text;
    nmudp1.RemotePort:=137;// NetBIOS-NS ,137端口
    MyStream:=TmemoryStream.Create;
    try
    MyStream.Write(t_ns, sizeof(t_ns));
    NMUDP1.SendStream(MyStream);
    finally
    MyStream.Free;
    end;
    end;
    下面是接收发送“UDP-NetBIOS-NS”应答包并分析和显示处理结果的代码。
    procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
    NumberBytes: Integer; FromIP: String; Port: Integer);
    var
    MyStream:TMemoryStream;
    mac_str:array[1..6]of byte;
    NumOfNames:byte;
    begin
    if numberbytes>0 then //如果接收的数据包字节数>0,则处理数据包
    begin
    MyStream:=TmemoryStream.Create;
    try
    NMUDP1.readstream(MyStream); //把接收到的数据包,读到内存中
    MyStream.Seek(56,SoFromBeginning);//定位至Number Of Names字段
    MyStream.Read(NumOfNames,1); //获取 Number Of Names字段的值MyStream.Seek(NumOfNames*18,soFromCurrent); //定位至Unit ID字段
    MyStream.Read(mac_str[1],6); //获取Unit ID字段的值
    edit4.Text:=inttohex(mac_str[1],2)+'-'+ //将目的主机的MAC地址格式化输出
    inttohex(mac_str[2],2)+'-'+
    inttohex(mac_str[3],2)+'-'+
    inttohex(mac_str[4],2)+'-'+
    inttohex(mac_str[5],2)+'-'+
    inttohex(mac_str[6],2);
    finally
    MyStream.Free;
    end;
    end;
    end;
      

  2.   

    7.0下没有tnmdup组件,装了dclsockets70.bpl也找不到呀
      

  3.   

    应该可以用api实现的,在网上搜索下应该能找到。
      

  4.   

    其实上边的功能还是可以使用api来完成的,或者考虑使用indy组件实现