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

Get PC IP address with Delphi XE2

Posted on 2012-03-12
Last Modified: 2012-03-13
Is there a simple way for a Delphi XE2 application to get the IP address of the PC where the application is running ?
Question by:LeTay
  • 4
  • 3
  • 2
  • +1
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37711431
uses winsock;
{$R *.dfm}

function LocalIP: string;
  TaPInAddr = array [0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
  phe: PHostEnt;
  pptr: PaPInAddr;
  Buffer: array [0..63] of Ansichar;
  i: Integer;
  GInitData: TWSADATA;
  WSAStartup($101, GInitData);
  Result := '';
  GetHostName(Buffer, SizeOf(Buffer));
  phe := GetHostByName(Buffer);
  if phe = nil then
  pptr := PaPInAddr(phe^.h_addr_list);
  i := 0;
  while pptr^[i] <> nil do
    Result := StrPas(inet_ntoa(pptr^[i]^));

procedure TForm1.Button1Click(Sender: TObject);

Open in new window

LVL 37

Accepted Solution

Geert Gruwez earned 500 total points
ID: 37713376
indy components include a component TIdIpWatch

Place on a form and IdIpWatch1.LocalIp to get your ip
or in a function:
function LocalIp: string;
var IPW: TIdIPWatch;
  Result := '';
  IpW := TIdIPWatch.Create(nil);
    if IpW.LocalIP <> '' then
      Result := IpW.LocalIP;

Open in new window


Author Closing Comment

ID: 37713645
Hello Geert, I wonder how you can find to for "productive" (making money) work seeing all the good answers/solutions you provide to the community !
Many thanks
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

LVL 21

Expert Comment

ID: 37713764
Delphi programming is a niche market.  Jobs are not always as readily available as they are with other languages, but they can pay very well.  Just in the last 3 months I have seen Delphi contracting jobs in the $65.00 - $80.00 per hour range ($130,000.00 - $160,000.00) per year.

This is yet another reason why I like Delphi.  I can take a 12 or 18 month contract and afford to have some time off!

Author Comment

ID: 37713769
You mean time off to help EE ?
LVL 37

Expert Comment

by:Geert Gruwez
ID: 37713805
i admit it is difficult to cram everything in a 24 hour day.
it helps if you only need 5 to 7 hours of sleep

while oracle things are installing i try and solve delphi questions on EE
currently i'm installing a lot :)

current job: oracle dba + sap basis 3 years
previous jobs: delphi developer 10 years,
  technician (plumbing, electricity, hvac, car mechanics in the weekend) 4 years
next job: don't know yet

old hobbies: martial arts (black belt), golf (handicap 9)
current hobby: house makeover, kids

you won't see me much in the weekends and evenings
i'm doing a makeover of our house
> currently the bathroom is 90% finished.
i didn't know a bathroom was so much work, been busy for 6 weeks now
the walk-in rain shower I installed actually works , no leaks !
my old job as a plumber is finally paying off :)

you can do anything you want, you just have to set your mind to it

Author Comment

ID: 37713818
Nice to read activities of Experts that often are in the shadow ...
For me Delphi is not the major task but the one I prefer
I live in Brussels, Belgium and I will retire in July but ... will continue working as consultant ...
LVL 37

Expert Comment

by:Geert Gruwez
ID: 37713826
nice to see a fellow country member
retirement ... nice,
by the time i get there, there will be no money left the way di rupo and the rest are going on
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 37713931
Mmm, I think that is simplest to use an embedded unit instead of a component coming from a huge component package.
Anyway, having already it installed, I agree that it's easy to use for this need

Author Comment

ID: 37713933
I think the opposite, on a code review point of view.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 67
Simple Delphi Question 9 96
URL for downloading Google Chrome for Win XP 2 187
Firemonkey webbrowser scrollbars ? 1 50
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 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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

829 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