求取本机MAC地址的Delphi代码,谢谢各位哥哥姐姐,祝你们长命百岁,越来越漂亮!!!!!

taolilia 2004-07-03 07:22:04
请问哪位知道Delphi如何调用arp协议吗?
我急死了,求求你们帮帮我吧,好不好呀?
要一个调用ARP协议把IP转成MAC地址或MAC地址转成IP的软件,,555
没事叫我做这个,,又不是不知道我是菜了,,我真想哭:(

...全文
206 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
aiirii 2004-07-04
  • 打赏
  • 举报
回复
远程机器的MAC查询(For Win2000)

function SendARP(DestIP: DWORD; SrcIP: DWORD; pMacAddr: PDWORD;
var PhyAddrLen: DWORD): DWORD;
stdcall; external 'IPHlpAPI.DLL';

function GetRemoteMACAddress(DestIP: string): string;
type
TInfo = array[0..7] of BYTE;
var
dwTargetIP: DWORD;
dwMacAddress: array[0..1] of DWORD;
dwMacLen: DWORD;
dwResult: DWORD;
X: TInfo;
begin
dwTargetIP := Inet_Addr(PChar(DestIP));
dwMacLen := 6;
dwResult := SendARP(dwTargetIP, 0, @dwMacAddress[0], dwMacLen);
if dwResult = NO_ERROR then
begin
X := TInfo(dwMacAddress);
Result := Format('%x%x%x%x%x%x',
[X[0], X[1], X[2], X[3], X[4], X[5]]);
end else Result := SysErrorMessage(dwResult);
end;

获得远程或本地机器的网卡的MAC noil0125(翻译) http://www.delphi3000.com/articles/article_3867.asp
aiirii 2004-07-04
  • 打赏
  • 举报
回复
Bardo:如何得知远程机器的MAC地址(并且不是代理的)?

kaneboy:我感觉没有任何方法,因为proxy的作用就是用proxy server去取数据,局域网内的电脑是不会直接和外面相 连的。即使是能透过proxy的http协议,也不能传递mac信息。要不要我将JAVA的方法贴你看?

wwwunix:呵呵,容易呀,向远程机发一个arp查询包就行了。如果他是通过代理上网,则根据网络的原理,除非在远程机器上装个服务,否则一般不能得到它的MAC。SendArp函数无法越过代理与防火墙,如何是好?
hemaliu 2004-07-04
  • 打赏
  • 举报
回复
学习ing 不过我讨厌看到很多鬼画符一样的东东啊
cctv6012cn 2004-07-04
  • 打赏
  • 举报
回复
看吧。好心人还是有很多的。楼主加油啊。我学习中
ma369 2004-07-03
  • 打赏
  • 举报
回复
学习
飞天揽月 2004-07-03
  • 打赏
  • 举报
回复
得到远程机器MAC地址源代码

#include
#include
#include
#include "iphlpapi.h"

#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "Iphlpapi.lib" )

void main( int argc, char ** argv )
{
int numberOfHost = 1;
struct hostent *remoteHostent;

//处理命令行参数
if ( argc == 3 )
numberOfHost = atoi( argv[2] );
if ( ( argc >3 ) || ( argc < 2 ) )
{
printf( "RmtHost v0.2 - Get remote HostName /MacAddress\n" );
printf( "by ShotgunLabs ( Shotgun@xici.net )\n\n" );
printf( "Usage :\n\tRmtHost.exe [RemoteIP]\n\n" );
printf( "Example:\n\tRmtHost.exe 192.168.0.3\n" );
printf( "\tRmtHost.exe 192.168.0.3 255\n\n" );
exit( 0 );
}

//初始化SOCKET
WSADATA wsaData;
int iRet = WSAStartup(MAKEWORD(2,1), &wsaData);
if ( iRet != 0 )
{
printf( "WSAStartup Error:%d\n", GetLastError() );
exit( 0 );
}
int nRemoteAddr = inet_addr( argv[1] );
remoteHostent= (struct hostent*)malloc( sizeof(struct hostent ));
struct in_addr sa;
for ( int i = 0; i < numberOfHost; i ++ )
{
//获取远程机器名
sa.s_addr = nRemoteAddr;
printf( "\nIpAddress : %s\n", inet_ntoa( sa ) );
remoteHostent = gethostbyaddr( (char*)&nRemoteAddr,4, AF_INET );
if ( remoteHostent )
printf( "HostName : %s\n",remoteHostent->h_name );
else
printf( "gethostbyaddr Error:%d\n",GetLastError() );
//发送ARP查询包获得远程MAC地址

unsigned char macAddress[6];
ULONG macAddLen = 6;
iRet=SendARP(nRemoteAddr, (unsigned long)NULL,(PULONG)&macAddress, &macAddLen);
if ( iRet == NO_ERROR )
{
printf( "MacAddress: " );
for( int i =0; i<6; i++ )
{
printf( "%.2x", macAddress[i] );
if ( i<5 ) printf( "-" );
}
printf( "\n" );
}
else
printf( "SendARP Error:%d\n", GetLastError());
nRemoteAddr = htonl( ntohl( nRemoteAddr ) + 1 );
}
}
飞天揽月 2004-07-03
  • 打赏
  • 举报
回复
uses nb30.pas 对了加上
飞天揽月 2004-07-03
  • 打赏
  • 举报
回复
//以下函数用以获得网卡地址。
function GetMACAddress(LanaNum: Byte; MACAddress: PMACAddress): Byte;
var
AdapterStatus: PAdapterStatus;
StatNCB: PNCB;
begin
New(StatNCB);
ZeroMemory(StatNCB, SizeOf(TNCB));
StatNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, StatNCB.ncb_length);
try
with StatNCB^ do
begin
ZeroMemory(MACAddress, SizeOf(TMACAddress));
ncb_buffer := PChar(AdapterStatus);
ncb_callname := '* ' + #0;
ncb_lana_num := Char(LanaNum);
ncb_command := Char(NCBASTAT);
NetBios(StatNCB);
Result := Byte(ncb_cmd_cplt);
if Result = NRC_GOODRET then
MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
end;
finally
FreeMem(AdapterStatus);
Dispose(StatNCB);
end;
end;
function GetLanaEnum(LanaEnum: PLanaEnum): Byte;
var
LanaEnumNCB: PNCB;
begin
New(LanaEnumNCB);
ZeroMemory(LanaEnumNCB, SizeOf(TNCB));
try
with LanaEnumNCB^ do
begin
ncb_buffer := PChar(LanaEnum);
ncb_length := SizeOf(TLanaEnum);
ncb_command := Char(NCBENUM);
NetBios(LanaEnumNCB);
Result := Byte(ncb_cmd_cplt);
end;
finally
Dispose(LanaEnumNCB);
end;
end;
taolilia 2004-07-03
  • 打赏
  • 举报
回复
谢谢你们啦,帮我找一点资料也好,,,谢谢!!!!

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧