?? _getmacdemo1.~pas
字號:
unit _GetMacDemo1;
interface
uses
nb30,
WinSock,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GDLL_NBGetAdapterAddress(a:integer):String;
function _SPGetIPAddress():string;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.lines.add('您的第'+edit1.text+'個適配器的MAC地址為:'+GDLL_NBGetAdapterAddress(StrtoIntdef(Edit1.Text,0)));
memo1.lines.add('您的IP地址為:'+_SPGetIPAddress());
end;
function GDLL_NBGetAdapterAddress(a:integer):String;
//a指定多個網卡適配器中的哪一個0,1,2...
Var
NCB:TNCB; // Netbios control block file://NetBios控制塊
ADAPTER : TADAPTERSTATUS; // Netbios adapter status//取網卡狀態
LANAENUM : TLANAENUM; // Netbios lana
intIdx : Integer; // Temporary work value//臨時變量
cRC : Char; // Netbios return code//NetBios返回值
strTemp : String; // Temporary string//臨時變量
Begin
// Initialize
Result := '';
Try
// Zero control blocl
ZeroMemory(@NCB, SizeOf(NCB));
// Issue enum command
NCB.ncb_command:=Chr(NCBENUM);
cRC := NetBios(@NCB);
// Reissue enum command
NCB.ncb_buffer := @LANAENUM;
NCB.ncb_length := SizeOf(LANAENUM);
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Reset adapter
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LANAENUM.lana[a];
cRC := NetBios(@NCB);
If Ord(cRC)<>0 Then
exit;
// Get adapter address
ZeroMemory(@NCB, SizeOf(NCB));
NCB.ncb_command := Chr(NCBASTAT);
NCB.ncb_lana_num := LANAENUM.lana[a];
StrPCopy(NCB.ncb_callname, '*');
NCB.ncb_buffer := @ADAPTER;
NCB.ncb_length := SizeOf(ADAPTER);
cRC := NetBios(@NCB);
// Convert it to string
strTemp := '';
For intIdx := 0 To 5 Do
strTemp := strTemp + InttoHex(Integer(ADAPTER.adapter_address[intIdx]),2);
Result := strTemp;
Finally
End;
end;
function _SPGetIPAddress():string;
var
ip :string;
ipstr :string;
ch :array [1..32] of char;
i :integer;
WSData:TWSAData;
MyHost:PHostEnt;
begin
result:='';
if WSAstartup(2,wsdata)<>0 then
begin
Exit;
end;
try
if getHostName(@ch[1],32)<>0 then
begin
Exit;
end;
except
begin
Exit;
end;
MyHost:=GetHostByName(@ch[1]);
if MyHost=NIL then
begin
Exit
end
else
begin
for i:=1 to 4 do
begin
ip:=inttostr(Ord(MyHost.h_addr^[i-1]));
ipstr:=ipstr+ip;
if i<4 then
ipstr:=ipstr+'.'
else
result:=ipstr;
end;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -