AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Namen der Netzwerk-Verbindungen auslesen
Thema durchsuchen
Ansicht
Themen-Optionen

Namen der Netzwerk-Verbindungen auslesen

Ein Thema von Helmi · begonnen am 1. Sep 2012 · letzter Beitrag vom 10. Okt 2016
 
Benutzerbild von Helmi
Helmi

Registriert seit: 29. Dez 2003
Ort: Erding, Republik Bayern
3.349 Beiträge
 
Delphi XE2 Professional
 
#12

AW: Namen der Netzwerk-Verbindungen auslesen

  Alt 27. Okt 2012, 18:31
Danke Danke Danke für die vielen Tips!

Irgendwie hab ich immer falsch gesucht (oder wie auch immer)

Ich hab jetzt mal was zusammengebastelt:

Delphi-Quellcode:
const
  MAX_ADAPTER_DESCRIPTION_LENGTH = 128; // arb.
  MAX_ADAPTER_NAME_LENGTH = 256; // arb.
  MAX_ADAPTER_ADDRESS_LENGTH = 8; // arb.

type
  PIP_ADDRESS_STRING = ^IP_ADDRESS_STRING;
  IP_ADDRESS_STRING = packed record
    acString: array [1..16] of AnsiChar;
  end;

  PIP_MASK_STRING = ^IP_MASK_STRING;
  IP_MASK_STRING = IP_ADDRESS_STRING;

  PIP_ADDR_STRING = ^IP_ADDR_STRING;
  IP_ADDR_STRING = packed record
    Next : PIP_ADDR_STRING;
    IpAddress: IP_ADDRESS_STRING;
    IpMask : IP_MASK_STRING;
    Context : DWORD;
  end;

  time_t = int64;

  PIP_ADAPTER_INFO = ^IP_ADAPTER_INFO;
  IP_ADAPTER_INFO = packed record
    Next : PIP_ADAPTER_INFO;
    ComboIndex : DWORD;
    AdapterName : array [1..MAX_ADAPTER_NAME_LENGTH + 4] of AnsiChar ;
    Description : array [1..MAX_ADAPTER_DESCRIPTION_LENGTH + 4] of AnsiChar;
    AddressLength : UINT;
    Address : array [1..MAX_ADAPTER_ADDRESS_LENGTH] of Byte;
    Index : DWORD;
    dwType : UINT;
    DhcpEnabled : UINT;
    CurrentIpAddress : PIP_ADDR_STRING;
    IpAddressList : IP_ADDR_STRING;
    GatewayList : IP_ADDR_STRING;
    DhcpServer : IP_ADDR_STRING;
    HaveWins : Boolean;
    PrimaryWinsServer : IP_ADDR_STRING;
    SecondaryWinsServer : IP_ADDR_STRING;
    LeaseObtained : time_t;
    LeaseExpires : time_t;
  end;

  function GetAdaptersInfo(const pAdapterInfo: PIP_ADAPTER_INFO; const pOutBufLen: PULONG): DWORD; stdcall;
    external 'IPHLPAPI.DLLname 'GetAdaptersInfo';

//http://msdn.microsoft.com/en-us/library/windows/desktop/aa365917(v=vs.85).aspx
procedure GetConnectionNameList(List: TStrings);
var
  pAdapterList: PIP_ADAPTER_INFO;
  dwLenAdapter: DWORD;
  ErrorCode : DWORD;

begin
  List.Clear;

  pAdapterList := nil; // Alles auf 0 ==> Benötigte Buffergrösse ermitteln
  dwLenAdapter := 0;

  ErrorCode := GetAdaptersInfo(pAdapterList, @dwLenAdapter);

  If ErrorCode <> ERROR_BUFFER_OVERFLOW then
    begin
      RaiseLastOSError(ErrorCode);

      exit;
    end;

  pAdapterList := AllocMem(dwLenAdapter);

  try
    ErrorCode := GetAdaptersInfo(pAdapterList, @dwLenAdapter);

    If ErrorCode <> ERROR_SUCCESS then
      begin
        RaiseLastOSError(ErrorCode);

        exit;
      end;


    while Assigned(pAdapterList) do
      begin
        List.Add(Format('AdapterName: %s', [String(pAdapterList.AdapterName)]));
        List.Add(Format('Descpription: %s', [String(pAdapterList.Description)]));
        List.Add(Format('ComboIndex: %d', [pAdapterList.ComboIndex]));
        List.Add(Format('AddressLength: %d', [pAdapterList.AddressLength]));
        List.Add(Format('Address: %d', [UInt64(pAdapterList.Address)]));
        List.Add(Format('Index: %d', [pAdapterList.Index]));
        List.Add(Format('dwType: %d', [pAdapterList.dwType]));
        List.Add(Format('DhcpEnabled: %d', [pAdapterList.DhcpEnabled]));
        List.Add(Format('IpAddressList.IpAddress: %s', [String(pAdapterList.IpAddressList.IpAddress.acString)]));
        List.Add(Format('IpAddressList.IpMask: %s', [String(pAdapterList.IpAddressList.IpMask.acString)]));
        List.Add(Format('IpAddressList.Context: %d', [pAdapterList.IpAddressList.Context]));
        List.Add(Format('GatewayList.IpAddress: %s', [String(pAdapterList.GatewayList.IpAddress.acString)]));
        List.Add(Format('GatewayList.IpMask: %s', [String(pAdapterList.GatewayList.IpMask.acString)]));
        List.Add(Format('GatewayList.Context: %d', [pAdapterList.GatewayList.Context]));
        List.Add(Format('DhcpServer.IpAddress: %s', [String(pAdapterList.DhcpServer.IpAddress.acString)]));
        List.Add(Format('DhcpServer.IpMask: %s', [String(pAdapterList.DhcpServer.IpMask.acString)]));
        List.Add(Format('DhcpServer.Context: %d', [pAdapterList.DhcpServer.Context]));
        List.Add(Format('IpAddressList.HaveWins: %d', [Integer(pAdapterList.HaveWins)]));
        List.Add(Format('PrimaryWinsServer.IpAddress: %s', [String(pAdapterList.PrimaryWinsServer.IpAddress.acString)]));
        List.Add(Format('PrimaryWinsServer.IpMask: %s', [String(pAdapterList.PrimaryWinsServer.IpMask.acString)]));
        List.Add(Format('PrimaryWinsServer.Context: %d', [pAdapterList.PrimaryWinsServer.Context]));
        List.Add(Format('SecondaryWinsServer.IpAddress: %s', [String(pAdapterList.SecondaryWinsServer.IpAddress.acString)]));
        List.Add(Format('SecondaryWinsServer.IpMask: %s', [String(pAdapterList.SecondaryWinsServer.IpMask.acString)]));
        List.Add(Format('SecondaryWinsServer.Context: %d', [pAdapterList.SecondaryWinsServer.Context]));

        List.Add('-------------------------------------------------------');

        pAdapterList := pAdapterList.Next;
      end;
   finally
     FreeMem(pAdapterList);
   end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  GetConnectionNameList(Memo1.Lines);
end;
Da les ich mir jetzt alles aus was GetAdaptersInfo zu bieten hat.
Nur, und jetzt bitte keine Schläge, in meinem ersten Post oben fragte ich nach dem Namen der Netzwerkverbindung - diese wird mir jetzt über GetAdaptersInfo nicht mehr angeboten. Kann man die über GetAdaptersInfo nicht auslesen? - muss ich dazu WMI benutzen?
Ich würd halt ungern zwei "verschiedene" Funktionen nutzen um eigentlich im gleichen Bereich (also Netzwerk) Daten auszulesen

[Edit]
In der Code-Libary findet man diesen Thread.
Damit könnt ich aus der Registry den Namen auslesen...
mfg
Helmi

>> Theorie ist Wissen, dass nicht funktioniert - Praxis ist, wenn alles funktioniert und keiner weiss warum! <<

Geändert von Helmi (27. Okt 2012 um 18:33 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:32 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz