How to quickly find a host device which is running homeassistant on it in local network?

I have a device in local network and installed home assistant , and used ngrok to support internet access.

I wanna to develop an application to access home assistant. How to detect that my app client and the home assistant server are in the same intranet network ,so switch to local ip to access it .

And how to check whether there is home assistant running in local intranet network with port 8123?

Why don’t you assign a static IP address to the device running HA?
Then all you’d need is a ping to see if the device is accessible (same network) or not?

for some reason , such a new user come to home, the app would automatic find the local home assistant server and use local IP to access it.
Just ping could not determine that it is a home assistant server. So if use http get timeout , it need too long to switch from internet to local network. And maybe user is in another intranet network which has the same IP
range such as 192.168.0.xxx, so just ip address is not able to do that.

then you’d have to resort to something like NMAP or similar?