Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi IP - Info basteln (https://www.delphipraxis.net/86043-ip-info-basteln.html)

sebjensen 8. Feb 2007 07:48


IP - Info basteln
 
Hallo,

ich wollte mich mal an den großen Bereich des Internetes ranwagen, mit einem kleinen Minitool. Dieses Tool soll eigentlich nichts besonderes können. Es soll nur die lokale IP-Adresse, die IP-Adresse im Web und die MAC-Adresse anzeigen.

Kann mir vielleicht jemand einen Tipp geben, wie ich diese Daten abfragen kann? Über cmd.exe und dann ipconfig erhält man ja auch die Informationen, aber wie kann ich diese Daten nun einbinden in Delphi?

Vielen Dank :stupid:

sebjensen

Klaus01 8. Feb 2007 08:16

Re: IP - Info basteln
 
Guten Morgen,

vielleicht helfen Dir diese Codeschnipsel ein wenig und ein Blick in diesen Thread könnte auch nicht schaden.

Delphi-Quellcode:
 
uses
 NB30;
...
 function GetRechnerName: string;
    var
      len: DWORD;
    begin
      len := MAX_COMPUTERNAME_LENGTH + 1;
      SetLength(result, len);
      if not Windows.GetComputerName(PChar(result), len) then
        RaiseLastWin32Error;
      SetLength(result, len);
    end; //function

  function GetAdapterInfo(Lana: Char): String;
    var
      Adapter: TAdapterStatus;
      NCB: TNCB;
    begin
      FillChar(NCB, SizeOf(NCB), 0);
      NCB.ncb_command := Char(NCBRESET);
      NCB.ncb_lana_num := Lana;
      if Netbios(@NCB) <> Char(NRC_GOODRET) then
      begin
        Result := 'mac not found';
        Exit;
      end;

      FillChar(NCB, SizeOf(NCB), 0);
      NCB.ncb_command := Char(NCBASTAT);
      NCB.ncb_lana_num := Lana;
      NCB.ncb_callname := '*';

      FillChar(Adapter, SizeOf(Adapter), 0);
      NCB.ncb_buffer := @Adapter;
      NCB.ncb_length := SizeOf(Adapter);
      if Netbios(@NCB) <> Char(NRC_GOODRET) then
      begin
        Result := 'mac not found';
        Exit;
      end;
      Result :=
        IntToHex(Byte(Adapter.adapter_address[0]), 2) + ':' +
        IntToHex(Byte(Adapter.adapter_address[1]), 2) + ':' +
        IntToHex(Byte(Adapter.adapter_address[2]), 2) + ':' +
        IntToHex(Byte(Adapter.adapter_address[3]), 2) + ':' +
        IntToHex(Byte(Adapter.adapter_address[4]), 2) + ':' +
        IntToHex(Byte(Adapter.adapter_address[5]), 2);
    end;

  function GetMACAddress: string;
    var
      AdapterList: TLanaEnum;
      NCB: TNCB;
    begin
      FillChar(NCB, SizeOf(NCB), 0);
      NCB.ncb_command := Char(NCBENUM);
      NCB.ncb_buffer := @AdapterList;
      NCB.ncb_length := SizeOf(AdapterList);
      Netbios(@NCB);
      if Byte(AdapterList.length) > 0 then
        Result := GetAdapterInfo(AdapterList.lana[0])
      else
        Result := 'mac not found';
    end;

  function GetLocalIPs: String;
    type PPInAddr= ^PInAddr;
    var
      wsaData : TWSAData;
      HostInfo : PHostEnt;
      HostName : Array[0..255] of Char;
      Addr    : PPInAddr;
    begin
      Result:='';
      if WSAStartup($0102, wsaData) <> 0 then
        Exit;
      try
        if GetHostName(HostName, SizeOf(HostName)) <> 0 then
          Exit;
        HostInfo:= GetHostByName(HostName);
        if HostInfo=nil then
          Exit;
        Addr:=Pointer(HostInfo^.h_addr_list);
        if (Addr=nil) or (Addr^=nil) then
          Exit;
        Result:=StrPas(inet_ntoa(Addr^^));
 //       inc(Addr);
 //       while Addr^ <> nil do begin
 //         Result:=Result+^M^J+StrPas(inet_ntoa(Addr^^));
 //         inc(Addr);
 //       end;
      finally
        WSACleanup;
      end;
    end;
Grüße
Klaus


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz