Recent

Author Topic: Know the hostname and IP  (Read 12367 times)

cpalx

  • Hero Member
  • *****
  • Posts: 606
Know the hostname and IP
« on: January 02, 2009, 05:36:15 pm »
if the program is running in a machine, how can i get the hostname and the IP?

thanks

cpalx

  • Hero Member
  • *****
  • Posts: 606
Re: Know the hostname and IP
« Reply #1 on: January 03, 2009, 10:42:31 pm »
i installed succesfully indy componets, is somebody knows how to use to obtein the local IP and its hostname?

cpalx

  • Hero Member
  • *****
  • Posts: 606
Re: Know the hostname and IP
« Reply #2 on: January 03, 2009, 10:50:13 pm »
i made it :D

we need TIdIPWatch  component from "Indy Misc Protocoles" palete

the lets active and in a button click event just write

showmessage( IdIPWatch.CurrentIP);

:D

i hope somebody helps

--
Christian

cpalx

  • Hero Member
  • *****
  • Posts: 606
Re: Know the hostname and IP
« Reply #3 on: January 03, 2009, 10:52:06 pm »
now, i need the hostname, i will continue watching

--
Christian

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Know the hostname and IP
« Reply #4 on: July 11, 2012, 07:16:04 am »
I would love to know how you can find your external IP as well.  Haven't found a cross-platform method yet using Synapse, Lnet or basic free pascal.

libya

  • New member
  • *
  • Posts: 7
Re: Know the hostname and IP
« Reply #5 on: January 24, 2013, 05:04:34 am »
if the program is running in a machine, how can i get the hostname and the IP?

thanks



Even though the program is running in a machine you can get your IP address from Ip-Details.com  By using that IP address you can get your hostname from the site WhoisXY.com  and it also shows your whois information.
« Last Edit: January 24, 2013, 05:15:48 am by libya »

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Know the hostname and IP
« Reply #6 on: January 24, 2013, 05:31:03 am »
You can use Tprocess to find the ip, host name, currently logged in user etc

and its cross platform dependant


just pass   ipconfig /all to a process and redirect output to your application, parse the information back
into your app

Look up my past post it goes into more details.

Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4

evoshroom

  • Full Member
  • ***
  • Posts: 157
Re: Know the hostname and IP
« Reply #7 on: January 24, 2013, 05:34:46 am »
Quote
You can use Tprocess to find the ip, host name, currently logged in user etc

and its cross platform dependant


just pass   ipconfig /all to a process and redirect output to your application, parse the information back
into your app

Look up my past post it goes into more details.

I doubt that works.  For example on OS X:

ipconfig getifaddr en0

That outputs my local IP, 192.168.1.101, not my Internet IP.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Know the hostname and IP
« Reply #8 on: January 24, 2013, 11:49:08 am »
Agreed with evoshroom.

IIRC, there is already sample code on the forum that queries e.g. whatismyip.com and gets the external IP address. You could use synapse, wget, whatever to get that.
Perhaps it's even on the wiki already - if not it might be a good addition.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Know the hostname and IP
« Reply #9 on: January 27, 2013, 12:25:25 pm »
FYI, modified a post by jostudio and added it here:
http://wiki.lazarus.freepascal.org/fphttpclient

Thanks, jostudio!

Hope people with synapse, indy etc examples will post it on the respective wiki pages and direct people with this recurring question there ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

wjackson153

  • Sr. Member
  • ****
  • Posts: 267
Re: Know the hostname and IP
« Reply #10 on: January 29, 2013, 04:29:49 am »
Will return your External IP  For linux

Code: [Select]
Procedure TForm1.Button1Click(Sender: TObject);
var
    hprocess: TProcess;

Begin

   hProcess := TProcess.Create(nil);
   hProcess.Executable := '/bin/sh';
   hprocess.Parameters.Add('-c');
   hprocess.Parameters.add('wget -q -O - http://myexternalip.com/raw');
   hProcess.Options := hProcess.Options + [poWaitOnExit, poUsePipes];
   hProcess.Execute;
   memo1.Lines.LoadFromStream(hprocess.Output);
   hProcess.Free;

 end;       

If anyone knows a way to store to a a string rather then a memo
another then pulling it from the memo then to a string


IE:   

var
ExternalIp: String;

begin
ExternalIP := hprocess.output;         // does not work it expects TinputPipeStream
end;
Lazarus 1.1 r39490 CT FPC 2.7.1 i386-linux KDE
Linux Mint 14 KDE 4