Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Get Local Network Adapter Addresses

See more Socket/SSL/TLS Examples

Demonstrates Socket.GetAdaptersAddresses, which populates a JsonObject with information about local network adapters, including IPv4 addresses, IPv6 addresses, and MAC addresses.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. This provides a portable way to enumerate the host's network interfaces and their addresses.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.JsonObject,
  Chilkat.Socket;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  socket: TSocket;
  json: TJsonObject;
  jsonStr: string;

begin
  success := False;

  socket := TSocket.Create;

  //  Populate a JsonObject with information about the local network adapters, including IPv4 addresses,
  //  IPv6 addresses, and MAC addresses.
  json := TJsonObject.Create;
  success := socket.GetAdaptersAddresses(json);
  if (success = False) then
    begin
      WriteLn(socket.LastErrorText);
      Exit;
    end;

  json.EmitCompact := False;
  jsonStr := json.Emit();
  WriteLn(jsonStr);
  //  JSON parsing code for this result can be generated at Chilkat's online tool:
  //  https://tools.chilkat.io/jsonParse


  socket.Free;
  json.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.