Advertisement
Guest User

Untitled

a guest
May 27th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #pragma comment (lib,"WS2_32.lib") //Potrzebne w Visual Studio
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <Windows.h>
  5. #include <WinSock.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     char hostName[128];
  13.     char hostAddress[128];
  14.     char inhostName[128];
  15.  
  16.     WSADATA ws;
  17.  
  18.     if (WSAStartup(MAKEWORD(1, 1), &ws) != 0)
  19.     {
  20.         cout << "Blad funkcji WSAStartup!" << endl;
  21.         getch();
  22.         return 0;
  23.     }
  24.     else
  25.         cout << "Zaladowano bibioteke WINSOCK." << endl;
  26.  
  27.     gethostname(hostName, sizeof(hostName));
  28.     cout << "Nazwa komputera :" << hostName << endl;
  29.     gethostbyaddr(hostAddress, sizeof(hostAddress), AF_INET);   //Śmieci ???
  30.     cout << "Nazwa komputera :" << hostAddress << endl;
  31.  
  32.     cout << "Podaj nazwe domeny ktorej IP chcesz pozyskac:";
  33.     cin >> inhostName;
  34.     cout << endl;
  35.  
  36.  
  37.  
  38.     hostent*host = gethostbyname(inhostName);
  39.     if (host == NULL)
  40.     {
  41.         cout << "Blad funkcji gethostbyname!" << endl;
  42.  
  43.     }
  44.     else
  45.     {
  46.         if (host->h_addrtype = AF_INET)
  47.         {
  48.             int i = 0;
  49.             in_addr address;
  50.             while (host->h_addr_list[i])
  51.             {
  52.                 address = (*(in_addr*)host->h_addr_list[i++]);
  53.                 cout << inet_ntoa(address) << endl;
  54.             }
  55.         }
  56.     }
  57.  
  58.     if (WSACleanup() != 0)
  59.     {
  60.         cout << "Blad funkcji WSACleanup!" << endl;
  61.     }
  62.     cout << "WSACleanup konczy korzystanie z Winsock" << endl;
  63.     getch();
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement