Discover Web Service in local private network with javascript

Viewed 470

I searched for a few options on my issue but couldn't find any useful information unfortunately.

Here is my issue:

Suppose I have 1x computer that runs a rest service on a specific port lets say 5555, running in a private network.

Now I have a frontend/browser application (javascript) that could be opened with a mobile phone or computer. When a device is connected to the same network (suppose wireless) and opens the frontend application it should discover in any way the rest service of the other computer, but I can't find a solution to that challenge.

So I can't find the sevices' ipv4 in the network since the webRTC workaround got smashed. I would have to traverse all possible private ip ranges to find that running service, which seems like an overkill.

Anyone got any idea how to solve this challenge?

2 Answers

Most web apps actually use the port-scan approach, which you are trying to avoid. I could think of some other approaches:

  • Have the service also publish an mDNS service under a specific name, e.g. foo.local. Your web app can simply have a static configuration using that hostname. This will, hovewer, require you to be able to control the service and your network/host need to be capable of using mDNS.
  • Require the admin of the service to register the local IP adress in a public DNS server. This will require manual config of the URL in the web app, but you can at least avoid dealing with discovering the address.

What you are talking about is sort of network scan, which is a security issue if you can do it, though it is usually possible in home networks. I would add a DNS server for that local network and use a local domain name to access the service. I don't know any other standard way to propagate where the service is.

Related