1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <Winsock2.h>
#include <windows.h>
#include <stdio.h>
#include <Ipexport.h>
#include <Icmpapi.h>
int main(){
HMODULE hICMP, hICMP2;
// Declare and initialize variables
char *SendData = "Data Buffer";
LPVOID ReplyBuffer;
DWORD dwRetVal;
HANDLE hIcmpFile;
PICMP_ECHO_REPLY *rep;
PIP_OPTION_INFORMATION *info;
hICMP = LoadLibrary("Iphlpapi.dll");
hICMP2 = LoadLibrary("Ws2_32.dll");
ReplyBuffer = (VOID*) malloc(sizeof(ICMP_ECHO_REPLY) + sizeof(SendData));
hIcmpFile = IcmpCreateFile();
if (hIcmpFile == INVALID_HANDLE_VALUE)
printf("\tUnable to open file.\n");
else
printf("\tFile created.\n");
if ((dwRetVal = IcmpSendEcho(hIcmpFile,
inet_addr("127.0.0.1"),
SendData, sizeof(SendData),
NULL, ReplyBuffer,
sizeof(ReplyBuffer) + sizeof(ICMP_ECHO_REPLY),
1000)) != 0) {
printf("\tReceived %ld messages.\n", dwRetVal);
//printf("\tMessage: %s\n", ReplyBuffer);
IcmpCloseHandle(hIcmpFile);
rep=(PICMP_ECHO_REPLY *)ReplyBuffer;
printf("time : %u\n",rep[2]);
info=(PIP_OPTION_INFORMATION *)rep[6];
printf("TTl : %u\n",(u_long)info[0]);
}
else {
printf("\tCall to IcmpSendEcho() failed.\n");
printf("\tError: %ld\n", GetLastError());
}
return 0;
} |
Partager