Re: [Lazarus] How to find out the public IP in code?
So much clean answer Slivio. Regards, Ara -- http://www.fastmail.com - Or how I learned to stop worrying and love email again -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How to find out the public IP in code?
On Sat, Nov 7, 2015 at 12:13 PM, fecske fecske wrote: > or see this > > http://forum.lazarus.freepascal.org/index.php/topic,17506.msg110917.html#msg110917 If you just want to get your external IP using some service like dyndns, you should use pure FCL: === begin code === uses fphttpclient, RegExpr; procedure TForm1.Button1Click(Sender: TObject); begin with TRegExpr.Create('[0-9.]+') do try if Exec(TFPHTTPClient.SimpleGet('http://checkip.dyndns.org')) then ShowMessage(Match[0]) finally Free; end; end; === end code == However, if you can use other service like echoip.com, just: === begin code === uses fphttpclient; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(TFPHTTPClient.SimpleGet('http://echoip.com/')); end; === end code === HTH -- Silvio Clécio -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How to find out the public IP in code?
or see this http://forum.lazarus.freepascal.org/index.php/topic,17506.msg110917.html#msg110917 On Sat, Nov 7, 2015 at 1:07 PM, Mark Morgan Lloyd wrote: > Bo Berglund wrote: >> >> I would like to be able to find out the public IP address of the Pi in >> a Lazarus program. >> How can this be accomplished? >> It is either connected to a wired or WiFi network router. >> in my browser I can go to http://checkip.dyndns.com/ and it will print >> a message with my IP address. >> But how is this done in code? > > > Avoid relying on this in the general case: you can usually use 0.0.0.0 to > represent "this host". The problem is that a machine might have multiple > physical Ethernet (or other) adapters, and in addition might have aliases > set up, and in the general case it's not easy to look at the list of IP > addresses and determine which one you want. > > http://forum.lazarus.freepascal.org/index.php?topic=20556.0 looks like a > good starting point, although it's oriented towards Windows. If you're > really looking for "/the/" address then I think you might end up parsing the > routing table (left as an exercise :-) and finding which local IP address > talks to the default gateway... which itself gets messy since there might be > multiple prioritised gateways. And then there's IP6 to consider. > > Word of advise: don't try arithmetic operations on IP addresses, and in > particular don't speculate on "next hops" etc. based on what you know about > your local network. > > -- > Mark Morgan Lloyd > markMLl .AT. telemetry.co .DOT. uk > > [Opinions above are the author's, not those of his employers or colleagues] > > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How to find out the public IP in code?
forexample http://wiki.lazarus.freepascal.org/Internet_Tools#Get_external_IP_address On Sat, Nov 7, 2015 at 1:07 PM, Mark Morgan Lloyd wrote: > Bo Berglund wrote: >> >> I would like to be able to find out the public IP address of the Pi in >> a Lazarus program. >> How can this be accomplished? >> It is either connected to a wired or WiFi network router. >> in my browser I can go to http://checkip.dyndns.com/ and it will print >> a message with my IP address. >> But how is this done in code? > > > Avoid relying on this in the general case: you can usually use 0.0.0.0 to > represent "this host". The problem is that a machine might have multiple > physical Ethernet (or other) adapters, and in addition might have aliases > set up, and in the general case it's not easy to look at the list of IP > addresses and determine which one you want. > > http://forum.lazarus.freepascal.org/index.php?topic=20556.0 looks like a > good starting point, although it's oriented towards Windows. If you're > really looking for "/the/" address then I think you might end up parsing the > routing table (left as an exercise :-) and finding which local IP address > talks to the default gateway... which itself gets messy since there might be > multiple prioritised gateways. And then there's IP6 to consider. > > Word of advise: don't try arithmetic operations on IP addresses, and in > particular don't speculate on "next hops" etc. based on what you know about > your local network. > > -- > Mark Morgan Lloyd > markMLl .AT. telemetry.co .DOT. uk > > [Opinions above are the author's, not those of his employers or colleagues] > > > -- > ___ > Lazarus mailing list > Lazarus@lists.lazarus.freepascal.org > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Re: [Lazarus] How to find out the public IP in code?
Bo Berglund wrote: I would like to be able to find out the public IP address of the Pi in a Lazarus program. How can this be accomplished? It is either connected to a wired or WiFi network router. in my browser I can go to http://checkip.dyndns.com/ and it will print a message with my IP address. But how is this done in code? Avoid relying on this in the general case: you can usually use 0.0.0.0 to represent "this host". The problem is that a machine might have multiple physical Ethernet (or other) adapters, and in addition might have aliases set up, and in the general case it's not easy to look at the list of IP addresses and determine which one you want. http://forum.lazarus.freepascal.org/index.php?topic=20556.0 looks like a good starting point, although it's oriented towards Windows. If you're really looking for "/the/" address then I think you might end up parsing the routing table (left as an exercise :-) and finding which local IP address talks to the default gateway... which itself gets messy since there might be multiple prioritised gateways. And then there's IP6 to consider. Word of advise: don't try arithmetic operations on IP addresses, and in particular don't speculate on "next hops" etc. based on what you know about your local network. -- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
[Lazarus] How to find out the public IP in code?
I would like to be able to find out the public IP address of the Pi in a Lazarus program. How can this be accomplished? It is either connected to a wired or WiFi network router. in my browser I can go to http://checkip.dyndns.com/ and it will print a message with my IP address. But how is this done in code? -- Bo Berglund Developer in Sweden -- ___ Lazarus mailing list Lazarus@lists.lazarus.freepascal.org http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus