SendARP的问题
__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;
}
############################################################
void __fastcall Tmain_::Button1Click(TObject *Sender)
{
String s;
s="124.168.1.66" ;
fromIPtoMAC(s);
ShowMessage(s);
}
#############################################################
问题是如果
尝试我同网关上机子,通过
124.168.1.66不在我网关上就不行
运行\\124.168.1.66打开好好的啊
why