begin process at 2012 05 29 19:54:29
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive C/C++

 > 

Archives

 > 

Réseau / Internet

 > 

obtenir son ip


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

obtenir son ip

samedi 25 octobre 2003 à 14:04:29 | obtenir son ip

bloops

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...
samedi 25 octobre 2003 à 20:59:38 | Re : obtenir son ip

ADPro22

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
samedi 25 octobre 2003 à 21:51:16 | Re : obtenir son ip

bloops


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...
dimanche 26 octobre 2003 à 03:52:21 | Re : obtenir son ip

mirlaine


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 <iphlpapi.h>
#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; i<pAdapt->AddressLength; 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+
dimanche 26 octobre 2003 à 08:56:42 | Re : obtenir son ip

bloops


ah merci beaucoup
vendredi 31 octobre 2003 à 13:42:15 | Re : obtenir son ip

vdox

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 ...
samedi 4 mars 2006 à 02:23:39 | Re : obtenir son ip

gasy72


je ne sais pas ce qui          ne vas pas mais ce programme ne fonct pas sur visual c++ il y a erreur
crois seulement


Cette discussion est classée dans : ip, idée, obtenir


Répondre à ce message

Sujets en rapport avec ce message

Obtenir IP avec email [ par goutbouyo ] Salut, J'ai fait un chat multiclient pour windows. Le problème c'est qu'il faut que chaque client rentre l'adresse IP de la personne avec qui il veut obtenir son ip (linux) [ par Anacr0x ] Comme le dit le titre, je cherche a obtenir l'IP de mon ordi sous linux (si possible avec QT ca sympa, mais je rêve pas trop)Je rencontre pas mal de d Obtenir l'adresse MAC d'une IP [ par metos ] Bonjour à tous,     J'ai une adresse IP, et je souhaiterais obtenir l'adresse MAC. Comment peut-on le faire en C?Merci d'avancemetos Obtenir l'IP d'une connexion réseaux sur XP [ par jbrek ] Obtenir l'IP d'une connexion réseaux sur XP sous VC++ ?Est-ce possible ? Y a plusieurs manières ? Obtenir l'IP d'une connexion réseaux sur XP [ par jbrek ] Obtenir l'IP d'une connexion réseaux sur XP sous VC++ ?Est-ce possible ? Y a plusieurs manières ? comment obtenir le nom d'un pc a partir de son ip? [ par malice120 ] comment obtenir le nom d'un pc a partir de son ip? Obtenir le hostname du client [ par Poppuledaimadoshi ] Bonjour, je commence dans la programmation réseau, et j'ai un petit problème. En effet, j'ai commencé un petit programme en C plus plus qui fait serve changement IP [ par Gendo ] Salut a tous, j'aimerais simplement savoir s'il y a un moyen "simple" sous visual C++ 6.0 pour changer l'ip d'une carte réseau.J'ai bien essayé de pas RAW SOCKET - IP - ICMP - Ping [ par dark1933 ] Salut à tous,Voici le code d'un programme qui envoye un ping (ici à Google), mais ne reçoit aucune réponse.La socket utilisée est du type : socket(AF_ RAW SOCKET - IP - Sendto() - Erreur 'WSAEADDRNOTAVAIL' [ par dark1933 ] Salut à tous,J'essaye désespérément d'envoyer un Ping en forgeant le datagramme IP adéquat.J'obtiens l'erreur "WSAEADDRNOTAVAIL" au moment de l'appel


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,952 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales