Solved

How to get a list of Local Ip Address

Posted on 2004-09-02
5
1,195 Views
1 Endorsement
Last Modified: 2016-01-07
I noticed that when i use the Indy Component IdTCPServer, when i click bindings, there is a combo box with a list of local Ip Addresses.  How would I go about getting that list?
1
Comment
Question by:ErikPhilips
5 Comments
 
LVL 6

Expert Comment

by:bpana
ID: 11968564
uses Winsock;

function getIPs: Tstrings;
type
  TaPInAddr = array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe: PHostEnt;
  pptr: PaPInAddr;
  Buffer: array[0..63] of Char;
  I: Integer;
  GInitData: TWSAData;
begin
  WSAStartup($101, GInitData);
  Result := TstringList.Create;
  Result.Clear;
  GetHostName(Buffer, SizeOf(Buffer));
  phe := GetHostByName(buffer);
  if phe = nil then Exit;
  pPtr := PaPInAddr(phe^.h_addr_list);
  I    := 0;
  while pPtr^[I] <> nil do
  begin
    Result.Add(inet_ntoa(pptr^[I]^));
    Inc(I);
  end;
  WSACleanup;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines := GetIps;
end;
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 125 total points
ID: 11968616
If you still use tIdTCPServer it's simple....

Just add IDSTack to the uses clause and us the GStack.LocalAddresses list

A little sample:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,  StdCtrls, IdBaseComponent, IdComponent, IdTCPServer,idstack;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ComboBox1: TComboBox;
    IdTCPServer1: TIdTCPServer;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
combobox1.Items := GStack.LocalAddresses;
combobox1.Items.Insert(0,'127.0.0.1');
end;

end.

F68 ;-)
0
 
LVL 4

Author Comment

by:ErikPhilips
ID: 11968635
Thanks, that should help other people on EE with the same question.  (Funny I didn't find a question like it on EE).  I was looking for the INDY approach, but its good to know there is more then 1 answer.
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 11968686
Glad to have helped you :)

BTW a suggestion for your next Indy needs: in program files\borland\delphiX\source\indy there are the indy source files...
sometimes seems to be hard to find Indy solutions even by googling or surfing the Indy project Web site too, so the best way is to find solutions looking directly the source code....

F68 ;-)
0
 

Expert Comment

by:eng khaled moh
ID: 41401061
thank for you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now