BOOL CAutoDlg::Ping()
{
typedef HANDLE (WINAPI * pCreate)(VOID);
typedef BOOL (WINAPI *pClose)(HANDLE);
typedef DWORD (WINAPI *pSend)(HANDLE,IPAddr,LPVOID,WORD,PIP_OPTION_INFORMATION,LPVOID,DWORD,DWORD);
pCreate pIcmpCreate;
pClose pIcmpClose;
pSend pSendIcmp;
HMODULE hIcmp=LoadLibrary("iphlpapi.dll");
pIcmpCreate=(pCreate)GetProcAddress(hIcmp,"IcmpCreateFile");
pIcmpClose=(pClose)GetProcAddress(hIcmp,"IcmpCloseHandle");
pSendIcmp=(pSend)GetProcAddress(hIcmp,"IcmpSendEcho");
HANDLE iHandle;
iHandle=pIcmpCreate();
IPAddr pAddr;
pAddr=(IPAddr)inet_addr("119.75.217.56");
icmp_echo_reply pData;
bool state=true;
for(int i=1;i<=4;i++)
{
pSendIcmp(iHandle,pAddr,NULL,0,NULL,(LPVOID)&pData,sizeof(icmp_echo_reply),0);
if (pData.Status==0)
{
pIcmpClose(iHandle);
return TRUE;
}
}
return FALSE;
}
使用iphlpapi动态链接库函数实现ping功能
最新推荐文章于 2024-08-27 10:59:17 发布