Home > Mobile >  Find the private ip of an express server
Find the private ip of an express server

Time:11-25

I have a node express server running on Machine 1 as (0.0.0.0) and some client applications running on Machine 2, 3, and so on... All machines are connected to the same Wi-Fi

How can I get the private IP of Machine 1 (which is running the express server), so that I can directly start calling the server APIs from client applications?

Note : I am using electron js in both server and client

CodePudding user response:

The short answer is that you can't. HTTP servers don't broadcast their addresses.

You need to run some other kind of service (on the same machine as the HTTP server) such as zeroconf to provide discovery.

Then you need the clients to use it to find the server. You're probably out of luck if your clients are written in browser-side JS and you'll need to go to another level of complexity. I think DNS-SD is the way forward there.

CodePudding user response:

There are a couple possibilities.

  1. You can assign a local IP address to your server that does not change and thus is known. For example, on my LAN, I configure the auto-IP assignment to avoid 192.168.1.200 - 192.168.1.255 and thus I can manually assign those IP addresses to devices for which I want to have a constant and known IP address. Then, you can just refer to the "known" local IP address from your clients as in http://192.168.1.201/somePath.

  2. You can configure local DNS (probably in your gateway router) so you can access your private server from your private LAN using a DNS name and combine this with option 1 so the IP address of your server won't change. You will need a router with this capability.

  3. You can use a resource discovery service such as Simple Service Discovery Protocol (built into Windows) or BonJour (built into MacOS, available for Windows) if your client has the capability to use these. Your server will advertise its services in the resource discovery system and the clients can query the system to find the server.

  • Related