IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Web & réseau Delphi Discussion :

infos sur le réseau (cartes, mac & ip)


Sujet :

Web & réseau Delphi

  1. #1
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut infos sur le réseau (cartes, mac & ip)
    Bonjour,

    J'utilise une petite routine (pas à moi) pour obtenir les infos sur mes cartes réseaux. Mais sur certains PC ça ne donne rien (juste "ligne trop longue")
    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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    var
      Error,
      BufLen      : DWORD;
      P             : Pointer;
      AdapterInfo   : PTIP_ADAPTER_INFO;
      Descr,
      LocalIP,
      GatewayIP,
      DHCPIP      : string;
      i           : integer;
    begin
      i:=1;
      if not Assigned( List ) then EXIT;
      List.Clear;
      BufLen := SizeOf( AdapterInfo^ );
      New( AdapterInfo );
      Error := GetAdaptersInfo( AdapterInfo, @BufLen );
      P := AdapterInfo;
      if Error = NO_ERROR then
      begin
        while P <> nil do
          with TIP_ADAPTER_INFO(P^) do
          begin
            SetLength( Descr, SizeOf( Description ) );
            Descr := Trim( string( Description ) );
            //
            if IPAddressList.IpAddress[1] <> #0 then
              LocalIP := IPAddressList.IpAddress
            else
              LocalIP := NULL_IP;
            //
            if GateWayList.IPAddress[1] <> #0 then
              GateWayIP := GatewayList.IPAddress
            else
              GateWayIP := NULL_IP;
            //
            if DHCPServer.IPAddress[1] <> #0 then
              DHCPIP := DHCPServer.IPAddress
            else
              DHCPIP := NULL_IP;
     
            {if mac=MacAddr2Str( TMacAddress( Address ), AddressLength )then
               result:=GatewayIP;   }
     
            if GatewayIP<>'0.0.0.0' then
               begin
                 dans_tableau(MacAddr2Str( TMacAddress( Address ), AddressLength ),'Mac #'+inttostr(i));
                 dans_tableau(GatewayIP,'IP #'+inttostr(i));
                 dans_tableau(Descr,'Type #'+inttostr(i));
                 dans_tableau(dhcp(MacAddr2Str( TMacAddress( Address ), AddressLength )),'DHCP #'+inttostr(i));
                 dans_tableau(vitesse (MacAddr2Str( TMacAddress( Address ), AddressLength )),'Vitesse #'+inttostr(i));
                 inc(i);
               end;
     
            List.Add( Descr );
            List.Add( Format(
              '%8.8x|%6s|%16s|%2d|%16s|%16s|%16s',
              [Index, AdaptTypes[aType],
              MacAddr2Str( TMacAddress( Address ), AddressLength ),
                DHCPEnabled, LocalIP, GatewayIP, DHCPIP] )
                );
            List.Add( '  ' );
            P := Next;  //  TIP_ADAPTER_INFO(P^).Next  points to next entry
          end // with
        end // while
      else
        List.Add( SysErrorMessage( Error ) );
      Dispose( AdapterInfo );
    Cette procédure était nickel ()

    Bon je ne laisse pas tomber alors je cherche avec les WMI et j'ai bien trouvé mais c'est vraiment moins bien et aussi ça marche pas à tous les coups.

    J'avais tout d'abord utilisé IPConfig/all (procédure pas à moi non plus) avec Delphi et parfois ça faisait planter le PC pas de résultat rien ()
    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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    const
        ReadBuffer = 2400;
    var
      Security            : TSecurityAttributes;
      ReadPipe,WritePipe  : THandle; 
      start              : TStartUpInfo; 
      ProcessInfo        : TProcessInformation; 
      Buffer              : Pchar; 
      BytesRead,Apprunning: DWord; 
    begin
      jauge.Position:=0;
      With Security do 
      begin 
          nlength            := SizeOf(TSecurityAttributes); 
          binherithandle      := true; 
          lpsecuritydescriptor:= nil; 
      end; 
      if Createpipe (ReadPipe, WritePipe,@Security, 0) then 
      begin 
          Buffer  := AllocMem(ReadBuffer + 1); 
          FillChar(Start,Sizeof(Start),#0); 
          start.cb          := SizeOf(start); 
          start.hStdOutput  := WritePipe; 
          start.hStdInput  := ReadPipe; 
          start.dwFlags    := STARTF_USESTDHANDLES +STARTF_USESHOWWINDOW; 
          start.wShowWindow := SW_HIDE; 
    
          if CreateProcess(nil,PChar('cmd /C ipconfig/all'),@Security,@Security,true,NORMAL_PRIORITY_CLASS,nil,nil,start,ProcessInfo) 
          then 
          begin 
                repeat 
                      Apprunning := WaitForSingleObject(ProcessInfo.hProcess,100);
                      jauge.Position:=jauge.Position+1;
                      if jauge.Position=100 then
                         jauge.Position:=0;
                      Application.ProcessMessages;
                until (Apprunning <> WAIT_TIMEOUT); 
                repeat 
                      BytesRead := 0; 
                      ReadFile(ReadPipe,Buffer[0], 
                      ReadBuffer,BytesRead,nil); 
                      Buffer[BytesRead]:= #0; 
                      OemToAnsi(Buffer,Buffer);
                      AMemo.Text := AMemo.text + String(Buffer);
                until (BytesRead < ReadBuffer);
          end;
          FreeMem(Buffer);
          CloseHandle(ProcessInfo.hProcess);
          CloseHandle(ProcessInfo.hThread); 
          CloseHandle(ReadPipe); 
          CloseHandle(WritePipe); 
      end;
      jauge.Position:=0;
    Voila donc ma situation, je cherche une méthode qui marche à tous les coups pour obtenir pour toutes les cartes réseaux son adresse MAC, son modèle, son adresse IP et si elle est en DHCP ou non.
    Ou savoir pourquoi ça marche ou pas


    Merci d'avance de votre aide et vos lumières

  2. #2
    Membre chevronné
    Avatar de free07
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    930
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ardèche (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 930
    Points : 1 960
    Points
    1 960
    Par défaut
    Tu a essayé la solution qui se trouve dans la FAQ ?

    http://delphi.developpez.com/faq/?pa...e-carte-reseau

    Ce serait intéressant de savoir si cela fonctionne à tous les coups.

  3. #3
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    Bonjour,

    Oui et ça ne fonctionne pas sur tous les PC (en windows 7)

    Ce qui me chiffonne c'est pourquoi ?

    Je ne vois pas de différence entres les ordi
    Il y a des procédures qui me donnent les infos IPv4 que si l'IPv6 est coché, et nous devons le décocher. Ca complique


    Merci de ton aide

  4. #4
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 036
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 67
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 036
    Points : 40 941
    Points
    40 941
    Billets dans le blog
    62
    Par défaut
    Bonjour,
    Bon je ne laisse pas tomber alors je cherche avec les WMI et j'ai bien trouvé mais c'est vraiment moins bien et aussi ça marche pas à tous les coups.
    les WindowsManagementInstrumentation me semblent pourtant être la meilleure piste , après tout il s'agit de ce qu'utilise Microsoft pour retrouver ces renseignements ! (ce n'est pas tout à fait très joli cet interfaçage et fait comprendre pourquoi la liste des bugs est si longue dans leur OS )

    as tu essayé quelque chose comme WMI Delphi Code Creator ? a minima tu l'installes sur le poste "récalcitrant" pour voir quelles infos peuvent ressortir.

    Ce que tu cherches , via les WMI se trouve en root\CIMV2 dans la classe Win32_NetworkAdapterConfiguration

    rapidement , j'ai obtenu ceci
    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
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
    //-----------------------------------------------------------------------------------------------------
    //     This code was generated by the Wmi Delphi Code Creator (WDCC) Version 1.8.4.0
    //     http://code.google.com/p/wmi-delphi-code-creator/
    //     Blog http://theroadtodelphi.wordpress.com/wmi-delphi-code-creator/
    //     Author Rodrigo Ruz V. (RRUZ) Copyright (C) 2011-2014 
    //----------------------------------------------------------------------------------------------------- 
    //
    //     LIABILITY DISCLAIMER
    //     THIS GENERATED CODE IS DISTRIBUTED "AS IS". NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED.
    //     YOU USE IT AT YOUR OWN RISK. THE AUTHOR NOT WILL BE LIABLE FOR DATA LOSS,
    //     DAMAGES AND LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS CODE.
    //
    //----------------------------------------------------------------------------------------------------
    program GetWMI_Info;
     
    {$APPTYPE CONSOLE}
     
    uses
      SysUtils,
      ActiveX,
      ComObj,
      Variants;
     
     
     
    // La classe Win32_NetworkAdapterConfiguration représente les attributs et les 
    // comportements 
    // d'une carte réseau. Cette classe a été complétée, et inclut désormais de nouvelles propriétés et méthodes qui prennent en charge l'administration 
    // des protocoles TCP/IP et sont indépendantes de la carte réseau.
     
    procedure  GetWin32_NetworkAdapterConfigurationInfo;
    const
      WbemUser            ='';
      WbemPassword        ='';
      WbemComputer        ='localhost';
      wbemFlagForwardOnly = $00000020;
    var
      FSWbemLocator : OLEVariant;
      FWMIService   : OLEVariant;
      FWbemObjectSet: OLEVariant;
      FWbemObject   : OLEVariant;
      oEnum         : IEnumvariant;
      iValue        : LongWord;
    begin;
      FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
      FWMIService   := FSWbemLocator.ConnectServer(WbemComputer, 'root\CIMV2', WbemUser, WbemPassword);
      FWbemObjectSet:= FWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration','WQL',wbemFlagForwardOnly);
      oEnum         := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
      while oEnum.Next(1, FWbemObject, iValue) = 0 do
      begin
        Writeln(Format('Caption        %s',[String(FWbemObject.Caption)]));// String
        Writeln(Format('Description    %s',[String(FWbemObject.Description)]));// String
        Writeln(Format('DHCPEnabled    %s',[String(FWbemObject.DHCPEnabled)]));// Boolean
        Writeln(Format('IPAddress      %s',[String(FWbemObject.IPAddress)]));// String
        Writeln(Format('IPEnabled      %s',[String(FWbemObject.IPEnabled)]));// Boolean
        Writeln(Format('MACAddress     %s',[String(FWbemObject.MACAddress)]));// Array of String
     
        Writeln('');
        FWbemObject:=Unassigned;
      end;
    end;
     
     
    begin
     try
        CoInitialize(nil);
        try
          GetWin32_NetworkAdapterConfigurationInfo;
        finally
          CoUninitialize;
        end;
     except
        on E:EOleException do
            Writeln(Format('EOleException %s %x', [E.Message,E.ErrorCode])); 
        on E:Exception do
            Writeln(E.Classname, ':', E.Message);
     end;
     Writeln('Press Enter to exit');
     Readln;      
    end.
    MVP Embarcadero
    Delphi installés : D3,D7,D2010,XE4,XE7,D10 (Rio, Sidney), D11 (Alexandria), D12 (Athènes)
    SGBD : Firebird 2.5, 3, SQLite
    générateurs États : FastReport, Rave, QuickReport
    OS : Window Vista, Windows 10, Windows 11, Ubuntu, Androïd

Discussions similaires

  1. Réponses: 2
    Dernier message: 21/02/2011, 22h27
  2. Réponses: 3
    Dernier message: 10/03/2009, 10h07
  3. MAC sur un réseau PC
    Par lelectronique.com dans le forum Apple
    Réponses: 2
    Dernier message: 06/06/2008, 18h58
  4. Réponses: 6
    Dernier message: 25/09/2007, 19h45
  5. Nouvelle connexion réseau sur la même carte réseau
    Par beegees dans le forum Windows XP
    Réponses: 2
    Dernier message: 30/11/2005, 14h40

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo