How to make dynamic private IP address static?

Viewed 177

A node js server is running on localhost on my PC. I am connecting this server to a mobile app with some IP(192.168.0.120:8044) for API requests. I am sharing this IP address by scanning a QR code in my desktop electron app by mobile application. So the first time I am able to get the server's IP by QR.

But when my Desktop boots again. The private IP might change to maybe 192.168.0.121

Is there any way in node.js to make this private IP static so my mobile device can always know where to send all API requests?. like creating a custom subdomain locally not exposed to the internet?

I know I can just go to the PC's setting and make Ip static. But in production, it might be a big issue to ask users to do so.

1 Answers

While it may be possible to go into the computer's config programatically and make the IP static, it would be better to structure the application not to require such a thing.

Since the client initially connects to the server with a QR code, you could have the server embed its hardware MAC address in the code, instead of (or in addition to) the server's IP. On the client, save the MAC address in the app's permanent storage.

Then, to connect to the server from the client, search through the LAN's ARP table to identify which (if any) IP addresses have that MAC address. If so, you've found it - if not, the server is offline.

Related