简体   繁体   English

如何使动态私有IP地址static?

[英]How to make dynamic private IP address static?

A node.js server is running on localhost on my PC. node.js 服务器正在我的 PC 上的本地主机上运行。 I am connecting this server to a mobile app with some IP( 192.168.0.120:8044 ) for API requests.我正在将此服务器连接到具有某些 IP( 192.168.0.120:8044 )的移动应用程序,用于 API 请求。 I am sharing this IP address by scanning a QR code in my desktop electron app by mobile application.我通过移动应用程序扫描桌面 electron 应用程序中的二维码来分享这个 IP 地址。 So the first time I am able to get the server's IP by QR.所以我第一次能够通过二维码获取服务器的 IP。

But when my Desktop boots again.但是当我的桌面再次启动时。 The private IP might change to maybe 192.168.0.121私人 IP 可能会更改为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?.在 node.js 中有什么方法可以使这个私有 IP static 以便我的移动设备始终知道将所有 API 请求发送到哪里? like creating a custom subdomain locally not exposed to the inte.net?比如在本地创建一个不暴露给 inte.net 的自定义子域?

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.我知道我可以将 go 设置为 881209537588 static。但在生产中,要求用户这样做可能是个大问题。

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.虽然可以通过编程方式将 go 添加到计算机的配置中并生成 IP static,但最好将应用程序构建为不需要这样的东西。

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.由于客户端最初使用二维码连接到服务器,您可以让服务器在代码中嵌入其硬件 MAC 地址,而不是(或除此之外)服务器的 IP。在客户端,将 MAC 地址保存在应用程序的永久存储。

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.然后,要从客户端连接到服务器,请搜索 LAN 的ARP 表以识别哪些(如果有)IP 地址具有该 MAC 地址。 If so, you've found it - if not, the server is offline.如果是,则您已找到它 - 如果不是,则服务器处于离线状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM