Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get a list of Local Ip Address

Posted on 2004-09-02
5
Medium Priority
?
1,363 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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

730 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