Solved

How to get a list of Local Ip Address

Posted on 2004-09-02
5
1,300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 23

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 23

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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