begin process at 2012 05 27 21:01:17
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseaux & Internet

 > TRACEROUTE (SANS RAW PING)

TRACEROUTE (SANS RAW PING)


 Information sur la source

Note :
4 / 10 - par 1 personne
4,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Réseaux & Internet Niveau :Initié Date de création :15/11/2003 Vu / téléchargé :7 209 / 490

Auteur : mirlaine

Ecrire un message privé
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
un traceroute tout con avec les api de icmp.dll

merci à aardman pour sa source sur l 'icmp...




Source

  • #include <windows.h>
  • #include <winsock.h>
  • #include <stdio.h>
  • #pragma comment(lib, "ws2_32.lib")
  • typedef unsigned long IPAddr;
  • typedef struct ip_option_information {
  • UCHAR Ttl;
  • UCHAR Tos;
  • UCHAR Flags;
  • UCHAR OptionsSize;
  • PUCHAR OptionsData;
  • } IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION;
  • typedef struct icmp_echo_reply {
  • IPAddr Address;
  • ULONG Status;
  • ULONG RoundTripTime;
  • USHORT DataSize;
  • USHORT Reserved;
  • PVOID Data;
  • IP_OPTION_INFORMATION Options;
  • } ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY;
  • typedef DWORD (WINAPI *ICMPSendEcho)(
  • HANDLE IcmpHandle,
  • IPAddr DestinationAddress,
  • LPVOID RequestData,
  • WORD RequestSize,
  • PIP_OPTION_INFORMATION RequestOptions,
  • LPVOID ReplyBuffer,
  • DWORD ReplySize,
  • DWORD Timeout
  • );
  • typedef HANDLE (WINAPI *ICMPCreateFile)(void);
  • typedef BOOL (WINAPI *ICMPCloseHandle)( HANDLE IcmpHandle);
  • ICMPSendEcho pIcmpSendEcho;
  • ICMPCreateFile pIcmpCreateFile;
  • ICMPCloseHandle pIcmpCloseHandle;
  • struct hostent *host;
  • struct ip_option_information ip_option;
  • SOCKADDR_IN Addr;
  • ICMP_ECHO_REPLY *replyinfo;
  • BOOL fonction()
  • {
  • HINSTANCE hIcmpDll;
  • hIcmpDll = LoadLibrary ("icmp.dll");
  • if (hIcmpDll != NULL)
  • {
  • pIcmpSendEcho = (ICMPSendEcho)GetProcAddress( hIcmpDll, "IcmpSendEcho" );
  • if( !pIcmpSendEcho )
  • {
  • return FALSE;
  • }
  • pIcmpCreateFile = (ICMPCreateFile)GetProcAddress( hIcmpDll, "IcmpCreateFile" );
  • if( !pIcmpCreateFile )
  • {
  • return FALSE;
  • }
  • pIcmpCloseHandle = (ICMPCloseHandle)GetProcAddress( hIcmpDll, "IcmpCloseHandle" );
  • if( !pIcmpCloseHandle )
  • {
  • return FALSE;
  • }
  • }
  • else
  • return FALSE;
  • FreeLibrary( hIcmpDll );
  • return TRUE;
  • }
  • int main(int argc,char *argv[])
  • {
  • int z;
  • HANDLE hICMP;
  • WSADATA wsa;
  • char *DataBuffer;
  • char *ReplyBuffer;
  • WORD size=0;
  • char *AddrIP = NULL;
  • if(argc!=3)
  • {
  • printf("%s destination + taille du packet",argv[0]);
  • return -1;
  • }
  • else
  • AddrIP = argv[1];
  • size = atoi(argv[2]);
  • if(size < 0 || size > 102400)
  • {
  • printf("%s destination + taille du packet (0 - 102400)",argv[0]);
  • return -1;
  • }
  • if((WSAStartup(0x02, &wsa))!=0)
  • {
  • printf("erreur WSAStartup %d",WSAGetLastError());
  • return -1;
  • }
  • if(!fonction())
  • {
  • printf("erreur fonction");
  • return -1;
  • }
  • hICMP = pIcmpCreateFile();
  • if(hICMP == INVALID_HANDLE_VALUE)
  • {
  • printf("erreur IcmpCreateFile %d",GetLastError());
  • return -1;
  • }
  • z=1;
  • do
  • {
  • ip_option.Ttl=(unsigned char)z;
  • host = gethostbyname(AddrIP);
  • if(host == NULL)
  • {
  • printf("erreur gethostbyname %d",WSAGetLastError());
  • return -1;
  • }
  • Addr.sin_addr.s_addr=*((u_long*)host->h_addr_list[0]);
  • ReplyBuffer = (char *)malloc(256+size+1);
  • DataBuffer = (char *)malloc(size+1);
  • memset(ReplyBuffer, 0, 256+size+1);
  • memset(DataBuffer, 'F', size);
  • if(!pIcmpSendEcho(
  • hICMP,
  • Addr.sin_addr.s_addr,
  • DataBuffer,
  • size,
  • &ip_option,
  • ReplyBuffer,
  • 256+size,
  • 2000))
  • {
  • if(GetLastError() == WSA_QOS_ADMISSION_FAILURE)
  • {
  • printf("%02d RTT: NULL,\tTTL: %d\t",z,replyinfo->Options.Ttl );
  • printf(" inconnu ");
  • break;
  • }
  • else
  • {
  • printf("erreur IcmpSendEcho %d",GetLastError());
  • return -1;
  • }
  • }
  • replyinfo = (struct icmp_echo_reply *)ReplyBuffer;
  • printf("%02d RTT: %dms\tTTL: %d\t",z,replyinfo->RoundTripTime,replyinfo->Options.Ttl );
  • host = gethostbyaddr((char *)&replyinfo->Address,4,PF_INET);
  • if ( host != 0)
  • printf(" %s\n",host->h_name);
  • else
  • printf(" %s\n",inet_ntoa(*(struct in_addr *) &replyinfo->Address));
  • z++;
  • }
  • while (!replyinfo->Status == 0);
  • pIcmpCloseHandle(hICMP);
  • WSACleanup();
  • free(ReplyBuffer);
  • free(DataBuffer);
  • return 0;
  • }
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#pragma comment(lib, "ws2_32.lib")

typedef unsigned long IPAddr;

typedef struct ip_option_information {  
	UCHAR Ttl;  
	UCHAR Tos;  
	UCHAR Flags;  
	UCHAR OptionsSize;  
	PUCHAR OptionsData;
} IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION;

typedef struct icmp_echo_reply {  
	IPAddr Address; 
	ULONG Status;  
	ULONG RoundTripTime;  
	USHORT DataSize;  
	USHORT Reserved; 
	PVOID Data;  
	IP_OPTION_INFORMATION Options;
} ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY;

typedef DWORD (WINAPI *ICMPSendEcho)(
  HANDLE IcmpHandle,
  IPAddr DestinationAddress,
  LPVOID RequestData,
  WORD RequestSize,
  PIP_OPTION_INFORMATION RequestOptions,
  LPVOID ReplyBuffer,
  DWORD ReplySize,
  DWORD Timeout
);

typedef HANDLE (WINAPI *ICMPCreateFile)(void);
typedef BOOL (WINAPI *ICMPCloseHandle)( HANDLE IcmpHandle);

ICMPSendEcho	pIcmpSendEcho;
ICMPCreateFile	pIcmpCreateFile;
ICMPCloseHandle pIcmpCloseHandle;

struct hostent *host;
struct ip_option_information ip_option;

SOCKADDR_IN Addr;
ICMP_ECHO_REPLY *replyinfo;

BOOL fonction()
{

HINSTANCE hIcmpDll;
hIcmpDll = LoadLibrary ("icmp.dll"); 
if (hIcmpDll != NULL)
    {
		pIcmpSendEcho = (ICMPSendEcho)GetProcAddress( hIcmpDll, "IcmpSendEcho" );
		if( !pIcmpSendEcho )
			{
			return FALSE;
			}

		pIcmpCreateFile = (ICMPCreateFile)GetProcAddress( hIcmpDll, "IcmpCreateFile" );
		if( !pIcmpCreateFile )
			{
			return FALSE;
			}
		pIcmpCloseHandle = (ICMPCloseHandle)GetProcAddress( hIcmpDll, "IcmpCloseHandle" );
		if( !pIcmpCloseHandle )
			{
			return FALSE;
			}
	}
else
	return FALSE;

FreeLibrary( hIcmpDll );

return TRUE;
}

int main(int argc,char *argv[])
{
int z;

HANDLE hICMP;
WSADATA wsa;

char *DataBuffer;
char *ReplyBuffer;

WORD size=0;
char *AddrIP = NULL;

if(argc!=3)
{
	printf("%s destination + taille du packet",argv[0]);
	return -1;
}
else
AddrIP	= argv[1];
size	= atoi(argv[2]);

if(size < 0 || size > 102400)
{
	printf("%s destination + taille du packet (0 - 102400)",argv[0]);
	return -1;
}

if((WSAStartup(0x02, &wsa))!=0)
{
	printf("erreur WSAStartup %d",WSAGetLastError());
	return -1;
}
	
if(!fonction())
{
	printf("erreur fonction");
	return -1;
}

hICMP = pIcmpCreateFile();
if(hICMP == INVALID_HANDLE_VALUE)
{
	printf("erreur IcmpCreateFile %d",GetLastError());
	return -1;
}

z=1;

do
{
	ip_option.Ttl=(unsigned char)z;

	host = gethostbyname(AddrIP);
	if(host == NULL)
	{
		printf("erreur gethostbyname %d",WSAGetLastError());
		return -1;
	}

	Addr.sin_addr.s_addr=*((u_long*)host->h_addr_list[0]);

	ReplyBuffer = (char *)malloc(256+size+1);
	DataBuffer = (char *)malloc(size+1);

	memset(ReplyBuffer, 0, 256+size+1);
	memset(DataBuffer, 'F', size);

	if(!pIcmpSendEcho(
		hICMP,
		Addr.sin_addr.s_addr, 
		DataBuffer, 
		size, 
		&ip_option, 
		ReplyBuffer, 
		256+size,
		2000))

			{
			if(GetLastError() == WSA_QOS_ADMISSION_FAILURE)
				{
				printf("%02d RTT: NULL,\tTTL: %d\t",z,replyinfo->Options.Ttl );
				printf(" inconnu ");
				break;
				}
			else
				{
				printf("erreur IcmpSendEcho %d",GetLastError());
				return -1;
				}
			}
		
	replyinfo = (struct icmp_echo_reply *)ReplyBuffer;

	printf("%02d RTT: %dms\tTTL: %d\t",z,replyinfo->RoundTripTime,replyinfo->Options.Ttl );

	host = gethostbyaddr((char *)&replyinfo->Address,4,PF_INET);
	if ( host != 0) 
		
        printf(" %s\n",host->h_name);
	else 
		printf(" %s\n",inet_ntoa(*(struct in_addr *) &replyinfo->Address));

z++;
}
while (!replyinfo->Status == 0);

pIcmpCloseHandle(hICMP);
WSACleanup();
free(ReplyBuffer);
free(DataBuffer);
return 0;

}

 Conclusion

je débute en c/c++ donc premier programe pas trop complex
laissez vos commentaires :)

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   Release
    • ping.exeTélécharger ce fichier [Réservé aux membres club]28 672 octets
  • ping.cTélécharger ce fichier [Réservé aux membres club]Voir ce fichier3 760 octets

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture FPORT (DONNE LE PID D'UN PORT OUVERT)
Source avec Zip Source avec une capture NETSTAT (API NATIVE)

 Sources de la même categorie

Source avec Zip Source avec une capture MINI SERVEUR HTTP [WINDOWS] par ganjarasta
Source avec Zip Source avec une capture CLIENT DE TEST MODBUS TCP par brunovan
Source avec Zip Source avec une capture SCANIP [ARP / ICMP] par ganjarasta
Source avec Zip Source avec une capture TRACEROUTE [WINPCAP] par ganjarasta
Source avec Zip SERVEUR MULTITHREAD [LINUX/WIN] par nipepsinicolas

Commentaires et avis

Commentaire de aardman le 15/11/2003 14:04:20

Salut,
Content que ca ai pu te servir!

Commentaire de roswell1947 le 17/11/2003 00:04:00

Salut,
moi aussi je débute en C/C++, et je pense que quelque commentaires dans t'a source serais le bien venu pour nous autres novices...
Mais c'est pas mal, continue comme ca...

@+

Commentaire de AirFoxOne le 26/10/2005 05:42:58

mauvaise copie de : http://www.sockets.com/ms_icmp.htm

Commentaire de hector61 le 12/11/2005 17:00:08

slt voilà le problème que j'ai eu en executant ton code:
error C2065: 'WSA_QOS_ADMISSION_FAILURE' : undeclared identifier

j'ai chercher par tout mais j'arrive pas à reseoudre ce bleme!!!
merci d'avance!!!

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,390 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales