Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment (lib,"WS2_32.lib") //Potrzebne w Visual Studio
- #include <iostream>
- #include <conio.h>
- #include <Windows.h>
- #include <WinSock.h>
- using namespace std;
- int main()
- {
- char hostName[128];
- char hostAddress[128];
- char inhostName[128];
- WSADATA ws;
- if (WSAStartup(MAKEWORD(1, 1), &ws) != 0)
- {
- cout << "Blad funkcji WSAStartup!" << endl;
- getch();
- return 0;
- }
- else
- cout << "Zaladowano bibioteke WINSOCK." << endl;
- gethostname(hostName, sizeof(hostName));
- cout << "Nazwa komputera :" << hostName << endl;
- gethostbyaddr(hostAddress, sizeof(hostAddress), AF_INET); //Śmieci ???
- cout << "Nazwa komputera :" << hostAddress << endl;
- cout << "Podaj nazwe domeny ktorej IP chcesz pozyskac:";
- cin >> inhostName;
- cout << endl;
- hostent*host = gethostbyname(inhostName);
- if (host == NULL)
- {
- cout << "Blad funkcji gethostbyname!" << endl;
- }
- else
- {
- if (host->h_addrtype = AF_INET)
- {
- int i = 0;
- in_addr address;
- while (host->h_addr_list[i])
- {
- address = (*(in_addr*)host->h_addr_list[i++]);
- cout << inet_ntoa(address) << endl;
- }
- }
- }
- if (WSACleanup() != 0)
- {
- cout << "Blad funkcji WSACleanup!" << endl;
- }
- cout << "WSACleanup konczy korzystanie z Winsock" << endl;
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement