Find IP address

What’s a way in Xojo for a program to:
a. find the IP address of the computer the app is running on
b. find the “outside world” IP address (on the “other side” of the router)

a) you can get away with just creating a new TCP Socket and reading the local address
You dont need to connect or anything

b) usually requires a service on the other side of the router that can look back at a request and say “your IP is …”

services like https://www.whatsmyip.org/

1 Like

is there a way to get your public ip address without any web service ?
as many of them are prone to dissapear sooner or later
using arp shell commands or something like that ?

possibly query your router for its external ip address

I would like to stay independant of the router.
I know my public ip address I don’t need any program to that !
I want to implement it in a xojo program, cross platform and rweb service and router independant … if possible.

I’ll probably just use ipify. Hopefully it’s not going anywhere soon.

short of asking the router or an external service I dont know of a way to get your public ip address

Here is the code I use:

#If TargetDesktop Or TargetWeb Then
  Var pubip As String
  Var sck As New HTTPSocket
  
  Try
    Var js As New JSONItem(sck.Get("http://ipinfo.io/json", 10))
    If js.hasname("ip") Then pubip = js.value("ip")   
    
  Catch RuntimeException
    pubip = ""
  End Try
  
  If sck <> Nil Then sck = Nil
  Return pubip
#EndIf
1 Like

ipinfo.io sounds like it’s the same sort of service as the one I mentioned, ipify.org.
I guess if one fails you can try the other! :wink:

having a list of several you can try if one fails is probably prudent