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.

94 lines
2.6 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. BYTE AddrBuffer[1000];
  19. BYTE AliasBuffer[1000];
  20. DWORD AddrBufLen = 1000;
  21. DWORD AliasBufLen = 1000;
  22. LPCSADDR_INFO lpCSAddrInfo = (LPCSADDR_INFO) AddrBuffer;
  23. LPSTR lpAliases = (LPSTR) AliasBuffer;
  24. GUID dnsGuid = SVCID_DOMAIN_TCP;
  25. char ** ppHostAliases;
  26. LPSTR lpTemp = NULL, lpAddress = NULL;
  27. BYTE Part1, Part2, Part3, Part4;
  28. DWORD Address;
  29. if ( argc != 2 )
  30. {
  31. printf( "\nUseage: ghbn <Address>\n" );
  32. return( -1 );
  33. }
  34. lpAddress = argv[1];
  35. lpTemp = strtok( lpAddress, "." );
  36. Part1 = atoi( lpTemp );
  37. lpTemp = strtok( NULL, "." );
  38. Part2 = atoi( lpTemp );
  39. lpTemp = strtok( NULL, "." );
  40. Part3 = atoi( lpTemp );
  41. lpTemp = strtok( NULL, "." );
  42. Part4 = atoi( lpTemp );
  43. ((LPBYTE) &Address)[0] = Part1;
  44. ((LPBYTE) &Address)[1] = Part2;
  45. ((LPBYTE) &Address)[2] = Part3;
  46. ((LPBYTE) &Address)[3] = Part4;
  47. WSAStartup( MAKEWORD(1, 1), &wsaData );
  48. lpHostEnt = gethostbyaddr( &Address, 4, 0 );
  49. if ( lpHostEnt )
  50. {
  51. DWORD iter = 0;
  52. printf( "\nHost address found for IP address %d.%d.%d.%d.\n",
  53. Part1, Part2, Part3, Part4 );
  54. printf( "Official name of host: %s\n", lpHostEnt->h_name );
  55. ppHostAliases = lpHostEnt->h_aliases;
  56. while ( *ppHostAliases )
  57. printf( "Alias name: %s\n", *ppHostAliases++ );
  58. printf( "Host address type: %d\n", lpHostEnt->h_addrtype );
  59. printf( "Length of addresses: %d\n", lpHostEnt->h_length );
  60. while ( lpHostEnt->h_addr_list[iter] )
  61. {
  62. printf( "Address %d\t: [%d.%d.%d.%d]\n",
  63. iter + 1,
  64. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][0],
  65. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][1],
  66. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][2],
  67. 0x00FF & (WORD) lpHostEnt->h_addr_list[iter][3] );
  68. iter++;
  69. }
  70. }
  71. else
  72. {
  73. printf( "\nNo host found for IP address %d.%d.%d.%d.\nError: %d",
  74. Part1, Part2, Part3, Part4, WSAGetLastError() );
  75. }
  76. WSACleanup();
  77. return( 0 );
  78. }