Solved

How to get a list of Local Ip Address

Posted on 2004-09-02
5
1,220 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 120
Comparing dates in Delphi. Greater than/ Less than 3 150
Delphi XE10 Round Image 2 123
Run video youtube webbrowse 10 61
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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