1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <winsock2.h>
typedef int socklen_t;
const char *const HOST = "www.google.dz";
int main(void)
{
int i;
#ifdef __WIN32__
WSADATA wsa_data;
WSAStartup(MAKEWORD(2, 2), &wsa_data);
#endif
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock == -1)
return 1;
struct sockaddr_in address;
struct hostent *h = gethostbyname(HOST);
address.sin_family = AF_INET;
address.sin_addr = *((struct in_addr*)h->h_addr);
printf("%d.%d.%d.%d\n",address.sin_addr.S_un.S_un_b.s_b1,address.sin_addr.S_un.S_un_b.s_b2,address.sin_addr.S_un.S_un_b.s_b3,address.sin_addr.S_un.S_un_b.s_b4);
return 0;
} |