谁有用DELPHI发ARP包的源代码
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061216102243111.html
我知道PACKET.dll里有个packetsendpacket,不知道参数如何填,请大侠指教,加分多多!
来混分
__published:
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private:
typedef unsigned long(__import __stdcall Fun_2ul2ulPtrTOul)(unsigned long,unsigned long,unsigned long*,unsigned long*);
Fun_2ul2ulPtrTOul *Func1;
bool fromIPtoMAC(String&);
public:
__fastcall Tmain_(TComponent* Owner);
###################################################################
bool Tmain_::fromIPtoMAC(String& S)
{ HINSTANCE hIphlpapiDll;
hIphlpapiDll=LoadLibrary("iphlpapi.dll");
if(hIphlpapiDll==NULL)
{
FreeLibrary(hIphlpapiDll);
S="好像没有找到iphlpapi.dll";
return false;
}
unsigned long Rt,L_id,*L_MAC,L_phyAddrLen;
Rt=-1;
L_id=inet_addr(S.c_str());// inet_appr #include <winsock2.h>
if(L_id==INADDR_NONE)
{
FreeLibrary(hIphlpapiDll);
S="无效IP地址--"+S;
return false;
}
__int64 x=0;
L_MAC=reinterpret_cast<unsigned long*>(&x);
L_phyAddrLen=6;
(FARPROC &)Func1=GetProcAddress (hIphlpapiDll,"SendARP");
Rt=Func1(L_id,0,L_MAC,&L_phyAddrLen);
if(Rt!=0)
{
FreeLibrary(hIphlpapiDll);
S="没找到机器--"+S;
return false;
}
String Str_MAC;
Str_MAC=IntToHex(x,8).SubString(1,12);
Str_MAC=Str_MAC.Length()<12?"0"+Str_MAC:Str_MAC;
S=S+" "+Str_MAC;
FreeLibrary(hIphlpapiDll);
return true;
}
关中刀客的这段代码,我没看明白,好像不完整,是否下面还有.要是能翻译成DELPHI就好了.
Windows 中可以直接发二层的包吗?(学习中...)
const INADDR_NONE = $FFFFFFFF;
function SendARP(const DestIP: DWord;
const SrcIP: DWord;
const pMacAddr: Pointer;
const PhyAddrLen: PULONG): DWord; stdcall; external 'IPHLPAPI.DLL' name 'SendARP';
function inet_addr(const cp: PChar): DWord; stdcall; external 'WS2_32.DLL' name 'inet_addr';
procedure TForm1.Button1Click(Sender: TObject);
var
dwResult: DWord;
ulIPAddr: DWord;
ulMACAddr: array[0..5] of Byte;
ulAddrLen: ULONG;
begin
ulIPAddr := inet_addr(PChar(Edit1.Text));
// ShowMessage(IntToHex(ulIPAddr, 8));
if ulIPAddr = INADDR_NONE then
begin
MessageDlg('Invalid IP address', mtError, [mbOK], 0);
Exit;
end;
ulAddrLen := 6;
dwResult := SendARP(ulIPAddr, 0, @ulMACAddr, @ulAddrLen);
if dwResult <> 0 then
begin
MessageDlg('Error in send ARP request', mtError, [mbOK], 0);
Exit;
end;
ShowMessage('MAC address : ' +
IntToHex(ulMACAddr[0], 2) + ':' +
IntToHex(ulMACAddr[1], 2) + ':' +
IntToHex(ulMACAddr[2], 2) + ':' +
IntToHex(ulMACAddr[3], 2) + ':' +
IntToHex(ulMACAddr[4], 2) + ':' +
IntToHex(ulMACAddr[5], 2));
end;
我来混分
谢谢ly_liuyang兄,这段代码是获取指定IP的MAC,这个我会,我要的是向指定IP发送ARP欺骗包,不知哪会大仙做过,望不吝赐教,或直接发至我的邮箱:mail@net9999.com,加分无数
俺用Delphi和wincap包写过一个,只是不知道放哪了。哪天找到了,就给你。不过,你自己也可以看看Wincap包,其实挺简单的。
用Delphi和wincap包中PacketReceivePacket函数接包时出现内存泄漏。
这是扫描什么原因?
ly_liuyang:
我测试过你的代码,在同一网段没有问题,隔网段就有ARP错误!得不到MAC
还请指教阿!
fengxue291080(为分而来。。。。。。),你说的“在同一网段没有问题,隔网段就有ARP错误!得不到MAC”,你补补网络基础方面的课吧。
arp协议是广播型的,是不能跨网段的
SendARP, 获取指定IP对应的MAC
不是楼主需要的