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 32 33 34 35 36 37 38
| #include <stdlib.h>
#include <stdio.h>
#include <winsock2.h>
int main(void)
{
puts("------------Commande systeme--------------------------------------------------");
system("ipconfig");
puts("\n\n----------Fonctions reseaux--------------------------------------------------\n");
// Voir : gethostname --> http://msdn.microsoft.com/en-us/library/windows/desktop/ms738527%28v=vs.85%29.aspx
// gethostbyname --> http://msdn.microsoft.com/en-us/library/windows/desktop/ms738524%28v=vs.85%29.aspx
// struct hostent --> http://msdn.microsoft.com/en-us/library/windows/desktop/ms738552%28v=vs.85%29.aspx
struct in_addr addr;
struct hostent *localhost;
int ret = -1;
char localname[1000] = {0};
// Demarrer les services de reseau
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
// Recuperer le nom du PC local
ret = gethostname( &(localname[0]), 999);
// Recuperer une structure decrivant un hote a partir de son nom
localhost = gethostbyname( &(localname[0]) );
// Extraire l'adresse
addr.s_addr = *(u_long *) localhost->h_addr_list[0];
// Affichage
printf("Host : %s (%d)\n", localname, ret);
printf("IP = %s", inet_ntoa( addr ) );
return 0;
} |
Partager