Obtenir son ip

cs_bloops Messages postés 5 Date d'inscription mercredi 18 juin 2003 Statut Membre Dernière intervention 27 octobre 2003 - 25 oct. 2003 à 14:04
gasy72 Messages postés 23 Date d'inscription jeudi 2 mars 2006 Statut Membre Dernière intervention 11 août 2006 - 4 mars 2006 à 02:23
salut,

j'aimerais savoir si qqn aurait une idée pour obtenir les ip de chaque interface sur un pc un truc a la ifconfig sous nux par exemple..

merci à tous pour vos idée...

6 réponses

ADPro22 Messages postés 126 Date d'inscription mercredi 18 juillet 2001 Statut Membre Dernière intervention 27 octobre 2004
25 oct. 2003 à 20:59
ipconfig sous win
ifconfig sous nux

sinon, avec winsock, tu peux jeter un coup d'oeil ici :
http://www.cppfrance.com/code.aspx?ID=9391

Cordialement,

ADPro22
0
cs_bloops Messages postés 5 Date d'inscription mercredi 18 juin 2003 Statut Membre Dernière intervention 27 octobre 2003
25 oct. 2003 à 21:51
c'est déjà plus ou moins la fonction que j'ai, le probleme est que si tu as plusieurs interface, exemple:

un mec qui a son modem 56k et donc une ip 1.2.3.4 et une carte réseau avec une ip 192.168.1.2, ce genre de fonction te renvera seulement l'ip de la carte réseau, moi ce que je voudrais faire c'est stocker les adresses de chaque interface dans différents char * ou quelque chose du genre...
0
mirlaine Messages postés 32 Date d'inscription samedi 9 août 2003 Statut Membre Dernière intervention 24 août 2005
26 oct. 2003 à 03:52
jai les source de ipconfig :)
-----------------------code-----------------------------------
/******************************************************************************\
* This is a part of the Microsoft Source Code Samples.
* Copyright 1996 - 1998 Microsoft Corporation.
* All rights reserved.
* This source code is only intended as a supplement to
* Microsoft Development Tools and/or WinHelp documentation.
* See these sources for detailed information regarding the
* Microsoft samples programs.
\******************************************************************************/

/*
Module Name:

Ipconfig.cpp

Abstract:

This module illustrates how to programmatically retrieve IP configuration
information similar to the IPCONFIG.EXE utility. It demonstrates how to use
the IP Helper APIs GetNetworkParams() and GetAdaptersInfo().

To execute this application, simply build the application using the Microsoft Visual C++
nmake.exe program generation utility to make an executable ipconfig.exe. After the
build is complete, simply execute the resulting ipconfig.exe program.

Author:

Jim Ohlund 21-Apr-98

Revision History:

*/

#pragma comment(lib, "IPHlpApi.Lib")

#include <windows.h>
#include
#include <stdio.h>
#include <time.h>

void main(void) {

DWORD Err;

PFIXED_INFO pFixedInfo;
DWORD FixedInfoSize = 0;

PIP_ADAPTER_INFO pAdapterInfo, pAdapt;
DWORD AdapterInfoSize;
PIP_ADDR_STRING pAddrStr;

//
// Get the main IP configuration information for this machine using a FIXED_INFO structure
//
if ((Err = GetNetworkParams(NULL, &FixedInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
printf("GetNetworkParams sizing failed with error %d\n", Err);
return;
}
}

// Allocate memory from sizing information if ((pFixedInfo (PFIXED_INFO) GlobalAlloc(GPTR, FixedInfoSize)) NULL)
{
printf("Memory allocation error\n");
return;
}
if ((Err GetNetworkParams(pFixedInfo, &FixedInfoSize)) 0)
{
printf("\tHost Name . . . . . . . . . : %s\n", pFixedInfo->HostName);
printf("\tDNS Servers . . . . . . . . : %s\n", pFixedInfo->DnsServerList.IpAddress.String);
pAddrStr = pFixedInfo->DnsServerList.Next;
while(pAddrStr)
{
printf("%52s\n", pAddrStr->IpAddress.String);
pAddrStr = pAddrStr->Next;
}

printf("\tNode Type . . . . . . . . . : ");
switch (pFixedInfo->NodeType)
{
case 1:
printf("%s\n", "Broadcast");
break;
case 2:
printf("%s\n", "Peer to peer");
break;
case 4:
printf("%s\n", "Mixed");
break;
case 8:
printf("%s\n", "Hybrid");
break;
default:
printf("\n");
}

printf("\tNetBIOS Scope ID. . . . . . : %s\n", pFixedInfo->ScopeId);
printf("\tIP Routing Enabled. . . . . : %s\n", (pFixedInfo->EnableRouting ? "yes" : "no"));
printf("\tWINS Proxy Enabled. . . . . : %s\n", (pFixedInfo->EnableProxy ? "yes" : "no"));
printf("\tNetBIOS Resolution Uses DNS : %s\n", (pFixedInfo->EnableDns ? "yes" : "no"));
} else
{
printf("GetNetworkParams failed with error %d\n", Err);
return;
}

//
// Enumerate all of the adapter specific information using the IP_ADAPTER_INFO structure.
// Note: IP_ADAPTER_INFO contains a linked list of adapter entries.
//
AdapterInfoSize = 0;
if ((Err = GetAdaptersInfo(NULL, &AdapterInfoSize)) != 0)
{
if (Err != ERROR_BUFFER_OVERFLOW)
{
printf("GetAdaptersInfo sizing failed with error %d\n", Err);
return;
}
}

// Allocate memory from sizing information if ((pAdapterInfo (PIP_ADAPTER_INFO) GlobalAlloc(GPTR, AdapterInfoSize)) NULL)
{
printf("Memory allocation error\n");
return;
}

// Get actual adapter information
if ((Err = GetAdaptersInfo(pAdapterInfo, &AdapterInfoSize)) != 0)
{
printf("GetAdaptersInfo failed with error %d\n", Err);
return;
}

pAdapt = pAdapterInfo;

while (pAdapt)
{
switch (pAdapt->Type)
{
case MIB_IF_TYPE_ETHERNET:
printf("\nEthernet adapter ");
break;
case MIB_IF_TYPE_TOKENRING:
printf("\nToken Ring adapter ");
break;
case MIB_IF_TYPE_FDDI:
printf("\nFDDI adapter ");
break;
case MIB_IF_TYPE_PPP:
printf("\nPPP adapter ");
break;
case MIB_IF_TYPE_LOOPBACK:
printf("\nLoopback adapter ");
break;
case MIB_IF_TYPE_SLIP:
printf("\nSlip adapter ");
break;
case MIB_IF_TYPE_OTHER:
default:
printf("\nOther adapter ");
}
printf("%s:\n\n", pAdapt->AdapterName);

printf("\tDescription . . . . . . . . : %s\n", pAdapt->Description);

printf("\tPhysical Address. . . . . . : ");
for (UINT i=0; iAddressLength; i++)
{
if (i == (pAdapt->AddressLength - 1))
printf("%.2X\n",(int)pAdapt->Address[i]);
else
printf("%.2X-",(int)pAdapt->Address[i]);
}

printf("\tDHCP Enabled. . . . . . . . : %s\n", (pAdapt->DhcpEnabled ? "yes" : "no"));

pAddrStr = &(pAdapt->IpAddressList);
while(pAddrStr)
{
printf("\tIP Address. . . . . . . . . : %s\n", pAddrStr->IpAddress.String);
printf("\tSubnet Mask . . . . . . . . : %s\n", pAddrStr->IpMask.String);
pAddrStr = pAddrStr->Next;
}

printf("\tDefault Gateway . . . . . . : %s\n", pAdapt->GatewayList.IpAddress.String);
pAddrStr = pAdapt->GatewayList.Next;
while(pAddrStr)
{
printf("%52s\n", pAddrStr->IpAddress.String);
pAddrStr = pAddrStr->Next;
}

printf("\tDHCP Server . . . . . . . . : %s\n", pAdapt->DhcpServer.IpAddress.String);
printf("\tPrimary WINS Server . . . . : %s\n", pAdapt->PrimaryWinsServer.IpAddress.String);
printf("\tSecondary WINS Server . . . : %s\n", pAdapt->SecondaryWinsServer.IpAddress.String);

struct tm *newtime;

// Display coordinated universal time - GMT
newtime = gmtime(&pAdapt->LeaseObtained);
printf( "\tLease Obtained. . . . . . . : %s", asctime( newtime ) );

newtime = gmtime(&pAdapt->LeaseExpires);
printf( "\tLease Expires . . . . . . . : %s", asctime( newtime ) );

pAdapt = pAdapt->Next;
}
}
-------------------------------end-------------------------------
a+
0
cs_bloops Messages postés 5 Date d'inscription mercredi 18 juin 2003 Statut Membre Dernière intervention 27 octobre 2003
26 oct. 2003 à 08:56
ah merci beaucoup :big)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
vdox Messages postés 5 Date d'inscription vendredi 10 octobre 2003 Statut Membre Dernière intervention 17 juin 2013
31 oct. 2003 à 13:42
Salut
Vous sauriez pas comment faire dans un programme pour récupérer les différentes IP qui sont sur l' ordi ...
J' utilise Cpp Builder 5 et quand j' essaye avec les sources présentes sur cppfrance je n' y arrive pas, je suis sur qu' il y a un objet dans builder que gère ça tout à fait correctement mais je ne trouve pas ...
svp une petite aide ...
0
gasy72 Messages postés 23 Date d'inscription jeudi 2 mars 2006 Statut Membre Dernière intervention 11 août 2006
4 mars 2006 à 02:23
je ne sais pas ce qui ne vas pas mais ce programme ne fonct pas sur visual c++ il y a erreur
crois seulement
0
Rejoignez-nous