mac address question? with delphi |
答題得分者是:max5020
|
jimmywu
一般會員 發表:41 回覆:37 積分:15 註冊:2006-12-12 發送簡訊給我 |
請問高手們: step1 : 我用 writeln 寫一行dos 指另令: 'CMD /C NBTSTAT -a '192.168.1.1' >> mac.txt ' ;並存檔為 : "batf.bat" text file step2: 接著 用 api : ShellExecute(handle, 'open', pchar(batf), Nil, Nil, SW_HIDE); 將'192.168.1.1'的pc之mac addr存入"mac.txt" strp3 : 接著 用 Readln指令嚐試讀出存於"mac.txt"中的mac addr ,並顯示於畫面 但需於step2與step3中作中斷畫面(like :showmessage or debug)才可執行step3否則僅執行到step2即 跳過,但"mac.txt"檔案是正確的,不知為何,請求指點迷津!謝謝! 編輯記錄
Coffee 重新編輯於 2009-05-05 17:07:02, 註解 分類為問題‧
|
max5020
資深會員 發表:30 回覆:277 積分:321 註冊:2003-06-04 發送簡訊給我 |
借花獻佛
function GetMACAddressAll: string; var AdapterList: TLanaEnum; NCB: TNCB; MAC: String; lana_num: integer; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBENUM); NCB.ncb_buffer := @AdapterList; NCB.ncb_length := SizeOf(AdapterList); Netbios(@NCB); MAC := ''; lana_num :=0; Result :=''; if Byte(AdapterList.length) > 0 then while (MAC<>'mac not found') do begin if Result='' then Result := Result MAC else Result := Result ', ' MAC; MAC := GetAdapterInfo(AdapterList.lana[lana_num]); lana_num := lana_num 1; end else Result := 'mac not found'; end; |
max5020
資深會員 發表:30 回覆:277 積分:321 註冊:2003-06-04 發送簡訊給我 |
不好意思, 少了這段!!
function GetAdapterInfo(Lana: Char): String; var Adapter: TAdapterStatus; NCB: TNCB; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBRESET); NCB.ncb_lana_num := Lana; if Netbios(@NCB) <> Char(NRC_GOODRET) then begin Result := 'mac not found'; Exit; end; FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBASTAT); NCB.ncb_lana_num := Lana; NCB.ncb_callname := '*'; FillChar(Adapter, SizeOf(Adapter), 0); NCB.ncb_buffer := @Adapter; NCB.ncb_length := SizeOf(Adapter); if Netbios(@NCB) <> Char(NRC_GOODRET) then begin Result := 'mac not found'; Exit; end; Result := IntToHex(Byte(Adapter.adapter_address[0]), 2) '-' IntToHex(Byte(Adapter.adapter_address[1]), 2) '-' IntToHex(Byte(Adapter.adapter_address[2]), 2) '-' IntToHex(Byte(Adapter.adapter_address[3]), 2) '-' IntToHex(Byte(Adapter.adapter_address[4]), 2) '-' IntToHex(Byte(Adapter.adapter_address[5]), 2); end; |
jimmywu
一般會員 發表:41 回覆:37 積分:15 註冊:2006-12-12 發送簡訊給我 |
|
pcboy
版主 發表:177 回覆:1838 積分:1463 註冊:2004-01-13 發送簡訊給我 |
改出 Delphi 7, Delphi 2009 都可用的版本 [code delphi] // Delphi 7, Delphi 2009 // // 取得所有 MAC (Delphi 7, 2009 測試都OK) // 要 uses NB30 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Nb30, StdCtrls; // 要有 Bb30 type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function GetAdapterInfo(Lana: Char): String; var Adapter: TAdapterStatus; NCB: TNCB; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBRESET); NCB.ncb_lana_num := AnsiChar(Lana); if Netbios(@NCB) <> Char(NRC_GOODRET) then begin Result := 'mac not found'; Exit; end; FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBASTAT); NCB.ncb_lana_num := AnsiChar(Lana); NCB.ncb_callname := '*'; FillChar(Adapter, SizeOf(Adapter), 0); NCB.ncb_buffer := @Adapter; NCB.ncb_length := SizeOf(Adapter); if Netbios(@NCB) <> Char(NRC_GOODRET) then begin Result := 'mac not found'; Exit; end; Result := IntToHex(Byte(Adapter.adapter_address[0]), 2) '-' IntToHex(Byte(Adapter.adapter_address[1]), 2) '-' IntToHex(Byte(Adapter.adapter_address[2]), 2) '-' IntToHex(Byte(Adapter.adapter_address[3]), 2) '-' IntToHex(Byte(Adapter.adapter_address[4]), 2) '-' IntToHex(Byte(Adapter.adapter_address[5]), 2); end; function GetMACAddressAll: string; var AdapterList: TLanaEnum; NCB: TNCB; MAC: String; lana_num: integer; begin FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBENUM); NCB.ncb_buffer := @AdapterList; NCB.ncb_length := SizeOf(AdapterList); Netbios(@NCB); MAC := ''; lana_num :=0; Result :=''; if Byte(AdapterList.length) > 0 then while (MAC<>'mac not found') do begin if Result='' then Result := Result MAC else Result := Result ', ' MAC; MAC := GetAdapterInfo(Char(AdapterList.lana[lana_num])); lana_num := lana_num 1; end else Result := 'mac not found'; end; procedure TForm1.FormCreate(Sender: TObject); begin Memo1.Text := GetMACAddressAll; end; end. [/code]
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案! 子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問! |
jimmywu
一般會員 發表:41 回覆:37 積分:15 註冊:2006-12-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |