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.

95 lines
2.3 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 <string.h>
  12. #include <rpc.h>
  13. #include <rpcdce.h>
  14. _cdecl
  15. main(int argc, char **argv)
  16. {
  17. WSADATA wsaData;
  18. struct hostent * lpHostEnt;
  19. char * lpTemp;
  20. BYTE AddrBuffer[1000];
  21. BYTE AliasBuffer[1000];
  22. DWORD AddrBufLen = 1000;
  23. DWORD AliasBufLen = 1000;
  24. LPCSADDR_INFO lpCSAddrInfo = (LPCSADDR_INFO) AddrBuffer;
  25. LPSTR lpAliases = (LPSTR) AliasBuffer;
  26. GUID dnsGuid = SVCID_DOMAIN_TCP;
  27. char ** ppHostAliases;
  28. BOOL fLoop = FALSE;
  29. if ( !( argc == 2 | argc == 3 ) )
  30. {
  31. printf( "\nUseage: ghbn <Name> [-l]\n" );
  32. return( -1 );
  33. }
  34. if ( argc == 3 )
  35. {
  36. if ( !_stricmp( argv[2], "-l" ) )
  37. fLoop = TRUE;
  38. else
  39. {
  40. printf( "\nUseage: ghbn <Name> [-l]\n" );
  41. return( -1 );
  42. }
  43. }
  44. Repeat :
  45. WSAStartup( MAKEWORD(1, 1), &wsaData );
  46. if ( fLoop )
  47. system( "pause" );
  48. lpHostEnt = gethostbyname( argv[1] );
  49. if ( lpHostEnt )
  50. {
  51. DWORD iter = 0;
  52. printf( "\nHost address found for %s.\n", argv[1] );
  53. printf( "Official name of host: %s\n", lpHostEnt->h_name );
  54. ppHostAliases = lpHostEnt->h_aliases;
  55. while ( *ppHostAliases )
  56. printf( "Alias name: %s\n", *ppHostAliases++ );
  57. printf( "Host address type: %d\n", lpHostEnt->h_addrtype );
  58. printf( "Length of addresses: %d\n", lpHostEnt->h_length );
  59. while ( lpHostEnt->h_addr_list[iter] )
  60. {
  61. printf( "Address %d\t: [%d.%d.%d.%d]\n",
  62. iter + 1,
  63. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][0],
  64. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][1],
  65. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][2],
  66. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][3] );
  67. iter++;
  68. }
  69. }
  70. else
  71. {
  72. printf( "\nNo host found for %s.\nError: %d", argv[1], WSAGetLastError() );
  73. }
  74. WSACleanup();
  75. if ( fLoop )
  76. goto Repeat;
  77. return( 0 );
  78. }