获取网卡物理地址出错,请高手指点(50分)

  • 主题发起人 主题发起人 landina
  • 开始时间 开始时间
L

landina

Unregistered / Unconfirmed
GUEST, unregistred user!
<br>procedure Tregistercode.getMacAddress(out AValue: OleVariant);<br>&nbsp; var<br>&nbsp; &nbsp; AdapterList: TLanaEnum;<br>&nbsp; &nbsp; NCB: TNCB;<br>begin<br>&nbsp; FillChar(NCB, SizeOf(NCB), 0);<br>&nbsp; NCB.ncb_command := Char(NCBENUM);<br>&nbsp; NCB.ncb_buffer := @AdapterList;<br>&nbsp; NCB.ncb_length := SizeOf(AdapterList);<br>&nbsp; Netbios(@NCB);<br>&nbsp; if Byte(AdapterList.length) &gt; 0 then<br>&nbsp; &nbsp; AValue := GetAdapterInfo(AdapterList.lana[0])<br>&nbsp; else<br>&nbsp; &nbsp; AValue := '应用服务器上未发现网卡!';<br>end;<br><br><br><br><br><br><br><br>&nbsp; function Tregistercode.GetAdapterInfo(Lana: Char): String;<br>&nbsp; var<br>&nbsp; &nbsp; Adapter: TAdapterStatus;<br>&nbsp; &nbsp; NCB: TNCB;<br>&nbsp; begin<br>&nbsp; &nbsp; FillChar(NCB, SizeOf(NCB), 0);<br>&nbsp; &nbsp; NCB.ncb_command := Char(NCBRESET);<br>&nbsp; &nbsp; NCB.ncb_lana_num := Lana;<br>&nbsp; &nbsp; if Netbios(@NCB) &lt;&gt; Char(NRC_GOODRET) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := 'mac not found';<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; FillChar(NCB, SizeOf(NCB), 0);<br>&nbsp; &nbsp; NCB.ncb_command := Char(NCBASTAT);<br>//此处如果为NCB.ncb_command := Char(NCBENUM);在联网和不联网的值不一样。<br>&nbsp; &nbsp; NCB.ncb_lana_num := Lana;<br>&nbsp; &nbsp; NCB.ncb_callname := '*';<br><br>&nbsp; &nbsp; FillChar(Adapter, SizeOf(Adapter), 0);<br>&nbsp; &nbsp; NCB.ncb_buffer := @Adapter;<br>&nbsp; &nbsp; NCB.ncb_length := SizeOf(Adapter);<br>&nbsp; &nbsp; if Netbios(@NCB) &lt;&gt; Char(NRC_GOODRET) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Result := 'mac not found';<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Result :=<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' +<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[1]), 2) + '-' +<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[2]), 2) + '-' +<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' +<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' +<br>&nbsp; &nbsp; &nbsp; IntToHex(Byte(Adapter.adapter_address[5]), 2);<br>&nbsp; end;
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=547525
 
后退
顶部