Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WinSockDNS-Oceniane_1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <winsock.h>
- #include <conio.h>
- #include <Windows.h>
- #include <locale.h>
- #include <iostream>
- #pragma comment(lib,"WS2_32.lib")
- using namespace std;
- class DNS {
- private:
- char buff[255];
- void showError() {
- char text[1024];
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, WSAGetLastError(), 0, text, sizeof(text), NULL);
- printf("%s\n", text);
- }
- public:
- DNS() {
- WSADATA ws;
- int result = WSAStartup(MAKEWORD(1, 0), &ws);
- if (result != 0)
- {
- printf("Błąd inicjalizacji funkcji WSAStartup\n");
- return;
- }
- showError();
- result = gethostname(buff, sizeof(buff));
- if (result != 0) {
- printf("Błąd inicjalizacji funkcji gethostname\n");
- return;
- }
- printf("Nazwa hosta: %s\n", buff);
- }
- ~DNS() {
- WSACleanup();
- showError();
- }
- void getIP(char *hostname){
- HOSTENT *h = gethostbyname(hostname);
- if (h != 0)
- {
- int i = 0;
- while (h->h_addr_list[i] != 0)
- printf("[%d]: %s\n", i, inet_ntoa(*(in_addr*)h->h_addr_list[i++]));
- }
- showError();
- }
- };
- int main()
- {
- setlocale(LC_ALL, "pl-PL");
- char hostname[255];
- DNS d;
- do {
- printf("Podaj nazwe domeny: ");
- cin >> hostname;
- d.getIP(hostname);
- _getch();
- system("cls");
- }
- while (hostname != "\n");
- d.~DNS();
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment