Solved

How to get a list of Local Ip Address

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 104
Performance of SQL statement 37 137
CheckListBox usage 3 80
Delphi, TImage, Png 2 17
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

680 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