Web App's public address

Happy Monday,

I need to show the IP address that my web app is listing on. This is for a web app run on an internal network, not open to the internet.

This should be easy, but I’m not seeing it. It is, however, Monday… and I haven’t drank enough coffee, so pardon me if I’m dumb today.

The address is whatever your server IP address is plus the port you assigned it to use. For example http://192.168.1.100:8080. If internally you use DNS then you can use the server name plus port number like bigserver.somecompany.com:8080. In Xojo you can specify the port you want to use if the default 8080 is not available.

If you are using Xojo Cloud then the above probably does not apply.

The following code is for a Desktop app, but it should work on a Web app:

Var ipAll() As String
Var txtUrl As String
// This will create a list of all IP addresses on system NICs
For sNic As Integer = 0 To ( System.NetworkInterfaceCount - 1 )
  ipAll.Add(System.NetworkInterface(sNic).IPAddress)
Next sNic
// This will output that list in human-readable format
Var YOUR_PORT_HERE As String = “80” // Set this to whatever port you’re listening on
For ip As Integer = 0 To ipAll.LastIndex
  If txtUrl<>"" Then txtUrl = txtUrl + EndOfLine
  txtUrl = txtUrl + "http://" + ipAll(ip) + If( YOUR_PORT_HERE<>”80”,  ":" + YOUR_PORT_HERE, “” ) // Only display port if not HTTP default of 80
Next ip

Hope that helps!

I Tom,
Yep, but what I’m not seeing is how to get the “whatever your server IP address is” when I don’t know what machine my customer will install it on.

Hi Edward,

I know I can do System.Networkinterface(x).ipaddress, but I am not sure which interface it may be using.

I guess you had better ask the customer…

or I suppose you can create a first run method to email you what the customers server IP address is.

Typically, Xojo listens on all interfaces unless you specify one. But if you could provide more details of your code or which objects you’re using, it would help. Thanks!

Yeah, this seems pretty simple to me so I’m puzzled with why I can’t figure this out.

If I were to setup a TCP/IP socket I could get it’s address easily enough.
I would have hoped I could have gotten session.url or app.address or app.host etc.

It would help if the App.URL property wasn’t always empty. I was chatting with someone about this. I thought there was a ticket, but I can’t find one.

I will reach out to you privately with the workaround.

1 Like

Have a look at This project

Thanks, Wayne.
The winning solution came from @Tim_Parnell

var theUrl as string = “http://”+Session.Header(“Host”)

Thanks, Tim… (again and again over the years!)