Форум: "Сети";
Текущий архив: 2004.04.18;
Скачать: [xml.tar.bz2];
ВнизMAC-адрес Найти похожие ветки
← →
Kremen © (2004-02-12 09:54) [0]Как узнать МАС-адрес сетевой, хотя бы моего компьютера?
← →
wal © (2004-02-12 10:07) [1]arp.exe
Или самому кидать arp-запросы (определение MAC по IP).
Работает не только для моего компьютера, а для любого, до которого броадкаст доберется.
С уважением.
← →
Kremen © (2004-02-12 10:11) [2]Спасибо.
А как програмно это сделать?
← →
Verg © (2004-02-12 10:45) [3]
> Kremen © (12.02.04 09:54)
> Как узнать МАС-адрес сетевой, хотя бы моего компьютера?
Все это есть в IPHlpApi.
Могу дать несколько прототипов (далкео не все):
unit IPHelper;
interface
uses Windows;
const
MAX_INTERFACE_NAME_LEN = 256;
MAX_TRANSPORT_NAME_LEN = 40;
MAX_MEDIA_NAME = 16;
MAX_PORT_NAME = 16;
MAX_DEVICE_NAME = 128;
MAX_PHONE_NUMBER_LEN = 128;
MAX_DEVICETYPE_NAME = 16;
MAXLEN_IFDESCR = 256;
MAXLEN_PHYSADDR = 8;
MIB_IF_TYPE_OTHER = 1;
MIB_IF_TYPE_ETHERNET = 6;
MIB_IF_TYPE_TOKENRING = 9;
MIB_IF_TYPE_FDDI = 15;
MIB_IF_TYPE_PPP = 23;
MIB_IF_TYPE_LOOPBACK = 24;
MIB_IF_TYPE_SLIP = 28;
MIB_IF_ADMIN_STATUS_UP = 1;
MIB_IF_ADMIN_STATUS_DOWN = 2;
MIB_IF_ADMIN_STATUS_TESTING = 3;
MIB_IF_OPER_STATUS_NON_OPERATIONAL = 0;
MIB_IF_OPER_STATUS_UNREACHABLE = 1;
MIB_IF_OPER_STATUS_DISCONNECTED = 2;
MIB_IF_OPER_STATUS_CONNECTING = 3;
MIB_IF_OPER_STATUS_CONNECTED = 4;
MIB_IF_OPER_STATUS_OPERATIONAL = 5;
type
TIPAddr = ULONG; // An IP address.
TIPMask = ULONG; // An IP subnet mask.
TIP_STATUS = ULONG; // Status code returned from IP APIs.
TMIB_IFROW = record
wszName : array[0..MAX_INTERFACE_NAME_LEN-1] of widechar;
dwIndex,
dwType,
dwMtu,
dwSpeed,
dwPhysAddrLen : DWORD;
bPhysAddr : array[0..MAXLEN_PHYSADDR-1] of BYTE; // Вот то, что тебе нужно
dwAdminStatus,
dwOperStatus,
dwLastChange,
dwInOctets,
dwInUcastPkts,
dwInNUcastPkts,
dwInDiscards,
dwInErrors,
dwInUnknownProtos,
dwOutOctets,
dwOutUcastPkts,
dwOutNUcastPkts,
dwOutDiscards,
dwOutErrors,
dwOutQLen,
dwDescrLen : DWORD;
bDescr : array[0..MAXLEN_IFDESCR-1] of BYTE;
end;
PMIB_IFROW = ^TMIB_IFROW;
TMIB_IFTABLE = record
dwNumEntries : DWORD;
table : array[0..0] of TMIB_IFROW;
end;
PMIB_IFTABLE = ^TMIB_IFTABLE;
TMIB_IPADDRROW = record
dwAddr,
dwIndex,
dwMask,
dwBCastAddr,
dwReasmSize : DWORD;
unused1,
unused2 : WORD;
end;
PMIB_IPADDRROW = ^TMIB_IPADDRROW;
TMIB_IPADDRTABLE = record
dwNumEntries : DWORD;
table : array[0..0] of TMIB_IPADDRROW;
end;
PMIB_IPADDRTABLE= ^TMIB_IPADDRTABLE;
//////////////////////////////////////////////////////////////////////////////
// //
// Gets the MIB-II IfTable //
// //
{Parameters
pIfTable
[out] Pointer to a buffer that receives the interface table as a MIB_IFTABLE structure.
pdwSize
[in, out] On input, specifies the size of the buffer pointed to by the pIfTable parameter.
On output, if the buffer is not large enough to hold the returned interface table,
the function sets this parameter equal to the required buffer size.
bOrder
[in] Specifies whether the returned interface table should be sorted in ascending order by
interface index. If this parameter is TRUE, the table is sorted.
Return Values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is one of the following error codes.
Return Code Description
ERROR_INSUFFICIENT_BUFFER The buffer pointed to by the pIfTable parameter is not large
enough.
The required size is returned in the DWORD variable pointed
to by the pdwSize parameter.
ERROR_INVALID_PARAMETER The pdwSize parameter is NULL, or GetIfTable is unable to
write to the memory pointed to by the pdwSize parameter.
ERROR_NOT_SUPPORTED This function is not supported on the operating system
in use on the local system.
Other Use FormatMessage to obtain the message string for the returned error.
}
//////////////////////////////////////////////////////////////////////////////
function GetIfTable(pIfTable : PMIB_IFTABLE; var pdwSize : ULONG; bOrder : BOOL): DWORD; stdcall;
{
Parameters
pIpAddrTable [out] Pointer to a buffer that receives the interface–to–IP address
mapping table as a MIB_IPADDRTABLE structure.
pdwSize [in, out] On input, specifies the size of the buffer pointed to by the
pIpAddrTable parameter.
On output, if the buffer is not large enough to hold the
returned mapping table, the function sets this parameter
equal to the required buffer size.
bOrder [in] Specifies whether the returned mapping table should be sorted
in ascending order by IP address.
If this parameter is TRUE, the table is sorted.
Return Values
If the function succeeds, the return value is NO_ERROR.
If the function fails, the return value is one of the following error codes.
Return Code Description
ERROR_INSUFFICIENT_BUFFER The buffer pointed to by the pIpAddrTable parameter is not
large enough. The required size is returned in the DWORD
variable pointed to by the pdwSize parameter.
ERROR_INVALID_PARAMETER The pdwSize parameter is NULL, or GetIpAddrTable is unable
to write to the memory pointed to by the pdwSize parameter.
ERROR_NOT_SUPPORTED This function is not supported on the operating system in
use on the local system.
Other Use FormatMessage to obtain the message string for the returned error.
}
function GetIpAddrTable(var TMIB_IPADDRTABLE; var pdwSize : ULONG; bOrder : BOOL): DWORD; stdcall;
function SendARP(DestIP:DWORD;SrcIP:DWORD; var pMacAddr{и это тоже}; var PhyAddrLen:DWORD):DWORD;stdcall;
function SetIfEntry(pIfRow : PMIB_IFROW // specifies interface and status
): DWORD; stdcall;
implementation
function GetIfTable; external "IPHLPAPI.DLL" name "GetIfTable";
function GetIpAddrTable; external "IPHLPAPI.DLL" name "GetIpAddrTable";
function SendARP; external "IPHLPAPI.DLL" name "SendARP";
function SetIfEntry; external "IPHLPAPI.DLL" name "SetIfEntry";
end.
Попробуй. Может даже работает...
← →
Kremen © (2004-02-12 10:55) [4]Спасибо
← →
Rouse_ © (2004-02-12 11:18) [5]А можно и через NetBios...
демокод ниже:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, NB30;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function GetMACAdress:String;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.GetMACAdress:String;
var
NCB : PNCB;
Adapter: PAdapterStatus;
URetCode: Pchar;
RetCode: char;
I: Integer;
Lenum: PlanaEnum;
_SystemID: String;
TMPSTR: String;
begin
Result:="";
_SystemID:="";
Getmem(NCB,sizeof(TNCB));
Fillchar(NCB^,Sizeof(TNCB),0);
Getmem(Lenum,sizeof(TLanaEnum));
Fillchar(Lenum^,Sizeof(TLanaEnum),0);
Getmem(Adapter,sizeof(TAdapterStatus));
Fillchar(Adapter^,Sizeof(TAdapterStatus),0);
Lenum.Length:=chr(0);
NCB.ncb_command:=chr(NCBENUM);
NCB.ncb_buffer:=pointer(Lenum);
NCB.ncb_length:=sizeof(Lenum);
RetCode:=Netbios(NCB);
i:=0;
repeat
Fillchar(NCB^,Sizeof(TNCB),0);
Ncb.ncb_command:= chr(NCBRESET);
Ncb.ncb_lana_num:=lenum.lana[I];
RetCode:= Netbios(Ncb);
Fillchar(NCB^,Sizeof(TNCB),0);
Ncb.ncb_command:= chr(NCBASTAT);
Ncb.ncb_lana_num:= lenum.lana[I];
Ncb.ncb_callname:="* ";
Ncb.ncb_buffer:=pointer(Adapter);
Ncb.ncb_length:=sizeof(TAdapterStatus);
RetCode:= Netbios(Ncb);
if (RetCode=chr(0)) or (RetCode=chr(6)) then begin
_SystemId:=SysUtils.inttohex(ord(Adapter.adapter_address[0]),2)+"-"+
SysUtils.inttohex(ord(Adapter.adapter_address[1]),2)+"-"+
SysUtils.inttohex(ord(Adapter.adapter_address[2]),2)+"-"+
SysUtils.inttohex(ord(Adapter.adapter_address[3]),2)+"-"+
SysUtils.inttohex(ord(Adapter.adapter_address[4]),2)+"-"+
SysUtils.inttohex(ord(Adapter.adapter_address[5]),2);
end;
inc(i);
until (I>=ord(Lenum.length)) or (_SystemID<>"00-00-00-00-00-00");
FreeMem(NCB);
FreeMem(Adapter);
FreeMem(Lenum);
GetMacAdress:=_SystemID;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Caption := GetMACAdress;
end;
end.
Желаю успехов
← →
SniZ © (2004-02-15 23:38) [6]а можно поискать на www.delphi3000.com
Страницы: 1 вся ветка
Форум: "Сети";
Текущий архив: 2004.04.18;
Скачать: [xml.tar.bz2];
Память: 0.49 MB
Время: 0.031 c