Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
Get IP from website url
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
IRC channel
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
how to change the color f...
by
Joanna
[
Today
at 03:23:43 am]
A "leisure" question on W...
by
Joanna
[
Today
at 03:20:06 am]
Big Numbers Math
by
woodybrison
[
Today
at 01:30:21 am]
Project fails on run but ...
by
jamie
[
Today
at 12:54:49 am]
Curling Pythagoras Tree: ...
by
Boleeman
[
Today
at 12:00:37 am]
Offical launch of the 1 B...
by
Gustavo 'Gus' Carreno
[March 28, 2024, 11:51:31 pm]
Ribbon bar in Lazarus 3.2...
by
wp
[March 28, 2024, 11:29:17 pm]
Free AI to use in local
by
BSaidus
[March 28, 2024, 10:57:23 pm]
how to search in rxmemory...
by
rcmz
[March 28, 2024, 10:19:54 pm]
Configure JCF messages
by
GordonFindlay
[March 28, 2024, 10:16:19 pm]
Poll: Watches and Display...
by
Martin_fr
[March 28, 2024, 10:15:08 pm]
Dialog ShowModal and an i...
by
d7_2_laz
[March 28, 2024, 09:51:39 pm]
JEDI error but unit compi...
by
Thaddy
[March 28, 2024, 09:30:33 pm]
Understanding and adjusti...
by
circular
[March 28, 2024, 09:09:56 pm]
Controlling the behavior ...
by
wp
[March 28, 2024, 08:29:28 pm]
Dynarray initialization p...
by
Thaddy
[March 28, 2024, 06:30:12 pm]
Zeos components. Had to c...
by
Fantablup
[March 28, 2024, 04:17:13 pm]
[SOLVED] Completion box s...
by
furious programming
[March 28, 2024, 04:12:26 pm]
[LAMW] How to create a ca...
by
af0815
[March 28, 2024, 03:48:16 pm]
Complex package installat...
by
wp
[March 28, 2024, 03:38:16 pm]
[SOLVED] Combined pointer...
by
CM630
[March 28, 2024, 02:48:41 pm]
Using KeyPress event, how...
by
Zvoni
[March 28, 2024, 02:24:42 pm]
a Unit problem?
by
Thaddy
[March 28, 2024, 01:56:12 pm]
Any upgrades to fpWeb pag...
by
marcov
[March 28, 2024, 12:50:25 pm]
Help needed with Cairo / ...
by
Roland57
[March 28, 2024, 12:25:16 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Get IP from website url (Read 3055 times)
Ericktux
Sr. Member
Posts: 345
Get IP from website url
«
on:
August 09, 2021, 05:59:40 am »
hello friends, how to get the ip of a certain url, for example:
of
www.google.com
i get
172.217.192.104
I do this by "ping" with cmd, but there will be some code that will facilitate this, thanks
Logged
rsz
New Member
Posts: 45
Re: Get IP from website url
«
Reply #1 on:
August 09, 2021, 06:59:35 am »
Hi, yes have a look at the example in the fcl-net package:
https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-net/examples/testdns.pp#L66
The functions you're looking for are ResolveName and HostAddrToStr.
Logged
Ericktux
Sr. Member
Posts: 345
Re: Get IP from website url
«
Reply #2 on:
August 09, 2021, 07:14:18 am »
hello friend, I just tried it and I get an error "netdb" is missing, I solve it and then another error "BaseUnix" is missing
Logged
trev
Global Moderator
Hero Member
Posts: 2020
Former Delphi 1-7, 10.2 user
Re: Get IP from website url
«
Reply #3 on:
August 09, 2021, 07:57:42 am »
You need to also add BaseUnix to your Uses clause.
Logged
marcov
Administrator
Hero Member
Posts: 11383
FPC developer.
Re: Get IP from website url
«
Reply #4 on:
August 09, 2021, 09:24:13 am »
Doing it via the resolve unit might be cross unix/windows portable.
Logged
Ericktux
Sr. Member
Posts: 345
Re: Get IP from website url
«
Reply #5 on:
August 14, 2021, 08:16:10 am »
hello friends, this code is working for me at the moment
Code: Pascal
[Select]
[+]
[-]
unit
Unit1
;
{$mode objfpc}{$H+}
interface
uses
Classes
,
SysUtils
,
Forms
,
Controls
,
Graphics
,
Dialogs
,
StdCtrls
,
resolve
;
type
{ TForm1 }
TForm1
=
class
(
TForm
)
Button1
:
TButton
;
Edit1
:
TEdit
;
Memo1
:
TMemo
;
procedure
Button1Click
(
Sender
:
TObject
)
;
private
public
end
;
var
Form1
:
TForm1
;
implementation
{$R *.lfm}
{ TForm1 }
function
GetHostByName
(
HostName
:
String
)
:
String
;
var
host
:
THostResolver
;
begin
host
:
=
THostResolver
.
Create
(
nil
)
;
if
host
.
NameLookup
(
HostName
)
then
result
:
=
host
.
AddressAsString
else
result
:
=
''
;
host
.
Free
;
end
;
procedure
TForm1
.
Button1Click
(
Sender
:
TObject
)
;
begin
//ShowMessage(GetHostByName('www.google.com'));
Memo1
.
Lines
.
Add
(
GetHostByName
(
Edit1
.
Text
)
)
;
end
;
end
.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Networking and Web Programming
»
Get IP from website url
TinyPortal
© 2005-2018