z.txt#include "windows.h" #include <stdio.h> void abc(char *p) { FILE *fp=fopen("z.txt","a+"); fprintf(fp,"%s\n",p); fclose(fp);} struct o { unsigned char Ttl;unsigned char a[7]; }; struct { DWORD Address; unsigned long Status,RoundTripTime; unsigned char a[8]; struct o Options; } E; HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent *phostent; DWORD d;char aa[100];struct o I;char bb[100];int z; HANDLE ( WINAPI *pIcmpCreateFile )( VOID ); BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE ); DWORD (WINAPI *pIcmpSendEcho)(HANDLE,DWORD,LPVOID,WORD,LPVOID,LPVOID,DWORD,DWORD); int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd,int nShow ) { hIcmp = LoadLibrary( "ICMP.DLL" ); WSAStartup( 0x0101, &wsa ); pIcmpCreateFile=GetProcAddress( hIcmp,"IcmpCreateFile"); pIcmpCloseHandle=GetProcAddress( hIcmp,"IcmpCloseHandle"); pIcmpSendEcho =GetProcAddress( hIcmp,"IcmpSendEcho" ); hIP = pIcmpCreateFile(); for ( z = 1; z<= 20 ; z++) { I.Ttl=(unsigned char)z; phostent = gethostbyname( "www.neca.com"); dwIPAddr = (DWORD *)( *phostent->h_addr_list ); pIcmpSendEcho(hIP,*dwIPAddr,0,0,&I,&E,sizeof(E),8000 ); d=E.Address; phostent = gethostbyaddr((char *)&d,4,PF_INET); if ( phostent != 0) strcpy(aa,phostent->h_name) ; else strcpy(aa,"no host name"); wsprintf(bb," RTT: %dms, TTL: %d",E.RoundTripTime,E.Options.Ttl ); strcat(aa,bb); abc(aa); if ( E.Options.Ttl ) break; } MessageBox(0,"over","hi",0); pIcmpCloseHandle( hIP ); FreeLibrary( hIcmp ); WSACleanup(); }
Download the source Codeno host name RTT: 241ms, TTL: 0 no host name RTT: 224ms, TTL: 0 border7-serial3-7.WestOrange.mci.net RTT: 798ms, TTL: 0 core2-fddi-0.WestOrange.mci.net RTT: 856ms, TTL: 0 core3.WestOrange.mci.net RTT: 841ms, TTL: 0 sprint-nap.WestOrange.mci.net RTT: 990ms, TTL: 0 sl-pen-2-F4/0.sprintlink.net RTT: 804ms, TTL: 0 sl-pen-7-F0/0.sprintlink.net RTT: 796ms, TTL: 0 sl-new2-1-S0-1544k.sprintlink.net RTT: 850ms, TTL: 0 cygnus.neca.com RTT: 803ms, TTL: 246
Move back to the Vijay Mukhi's Technology Cornucopia Page to learn more about the other new Internet Technologies.