Bonjour,
je cherche a récupérer mon adresse IP du point de vue de mon réseau....
Je voudrais obtenir, par exemple, 192.168.0.x et non 127.0.0.1
Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> #include <netdb.h> void view_ip() { char s[256]; struct hostent *host; struct in_addr **adr; if (!gethostname(s, 256)) if ((host = gethostbyname(s)) != NULL) for (adr = (struct in_addr **)host->h_addr_list; *adr; adr++) printf("IP : %s\n", inet_ntoa(**adr)); }![]()
Partager