Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winsock2.h>
  6. #include <wsipx.h>
  7. #include <svcguid.h>
  8. #include <nspapi.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <rpc.h>
  12. #include <rpcdce.h>
  13. _cdecl
  14. main(int argc, char **argv)
  15. {
  16. WSADATA wsaData;
  17. struct hostent * lpHostEnt;
  18. char * lpTemp;
  19. BYTE AddrBuffer[1000];
  20. BYTE AliasBuffer[1000];
  21. DWORD AddrBufLen = 1000;
  22. DWORD AliasBufLen = 1000;
  23. LPCSADDR_INFO lpCSAddrInfo = (LPCSADDR_INFO) AddrBuffer;
  24. LPSTR lpAliases = (LPSTR) AliasBuffer;
  25. GUID dnsGuid = SVCID_DOMAIN_TCP;
  26. char ** ppHostAliases;
  27. DWORD iter;
  28. if ( argc != 2 )
  29. {
  30. printf( "\nUseage: ghbn <Name>\n" );
  31. return( -1 );
  32. }
  33. WSAStartup( MAKEWORD(1, 1), &wsaData );
  34. system( "pause" );
  35. for ( iter = 0; iter < 10000; iter ++ )
  36. {
  37. lpHostEnt = gethostbyname( argv[1] );
  38. }
  39. system( "pause" );
  40. if ( lpHostEnt )
  41. {
  42. DWORD iter = 0;
  43. printf( "\nHost address found for %s.\n", argv[1] );
  44. printf( "Official name of host: %s\n", lpHostEnt->h_name );
  45. ppHostAliases = lpHostEnt->h_aliases;
  46. while ( *ppHostAliases )
  47. printf( "Alias name: %s\n", *ppHostAliases++ );
  48. printf( "Host address type: %d\n", lpHostEnt->h_addrtype );
  49. printf( "Length of addresses: %d\n", lpHostEnt->h_length );
  50. while ( lpHostEnt->h_addr_list[iter] )
  51. {
  52. printf( "Address %d\t: [%d.%d.%d.%d]\n",
  53. iter + 1,
  54. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][0],
  55. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][1],
  56. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][2],
  57. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][3] );
  58. iter++;
  59. }
  60. }
  61. else
  62. {
  63. printf( "\nNo host found for %s.\nError: %d", argv[1], WSAGetLastError() );
  64. }
  65. WSACleanup();
  66. return( 0 );
  67. }