How to make dynamic private IP address static? - node.js

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.

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

node js send html to network rather than only localhost server

I'm using node js trying to send my web-page to my network, I successfully call localhost:port in my computer using express as server, the webpage loads fine trigger my webcam which I used to streaming in the webpage, and then im working to make a simple app in my phone to directly access my server, so my questions:
1.How do I able to access my server from different devices in the same wireless-network? by calling ip + port ?192.168.1.104:9001 ? cause i've tried and it didnt work.
2.I've found https with .pem something like that, is that the answer ? is there also any other way ?
3.maybe any advice before i work to make my web-app to devices? using koa? i don't even really know what is that, but i'm happily take any advices.
EDIT: i've read How could others, on a local network, access my NodeJS app while it's running on my machine?
let's say I simply using random router, so i can't configure my router-port, my server in my pc and my phone join in the same network, trying to access the server in my phone
1.How do I able to access my server from different devices in the same wireless-network?
All you need to do is find your server's IP address in this same wireless-network, and find the Node.js application's port. Then access the following URL in other devices:
http://{server_IP}:{port}
However, there are some points need to check:
Need to check firewall and confirm the port is not blocked, server IP is not blocked by test device, and test device IP is not blocked by server.
Need to check whether there is any Proxy setting in server and test device. If there is any, disable the proxy.
A computer may have many IP addresses at the same time, you need to find the correct one in the same wireless-network. For example, If you install a virtual machine software such as VMware and run a virtual system inside, your real computer will get IP address as 192.168.*.* -- this IP address looks like an intranet IP in wireless-network, but it is not, and can never be accessed by test device.
2.I've found https with .pem something like that, is that the answer?
No, HTTPS has nothing to do with this problem. HTTPS just add security (based on HTTP layer), it does not impact any HTTP connectivity. Actually, to minify the problem, it is better to only use HTTP in your scenario.
There is only one very special case that may bring your problem by HTTPS -- the test machine is configured and will block any non-HTTPS connection for security.
3.maybe any advice before i work to make my web-app to devices? using koa?
My suggestion is: As there is an HTTP connectivity issue, the first step is trying to find the root cause of that issue. Thus, it is better to make a simplest HTTP server using native Node.js, no Koa, no Express. In this way, the complexity of server will be reduced, which makes root cause investigation easier.
After the HTTP connectivity issue is fixed, you can pick up Koa or Express or any other mature Node.js web framework to help the web-app work.
4.let's say I simply using random router, so i can't...
Do you mean your server get dynamic IP address by DHCP? As long as the IP is not blocked by test device, it does not matter.

How to share web application on linux?

I host a web application on my laptop and I access it using 'localhost:9080/abc.com' and lets assume my IP is '192.168.10.20'
Now, I want my colleague to access this web application from his system 'web browser' by typing in '192.168.10.20:9080/abc.com'
As laptop is owned by 'company' I cannot install (or) use any third party softwares
How can I manage this on RHEL 6?
Assuming you're on the same network (LAN) then a client who connects to 192.168.10.20:9080 should have no problems (assuming the web aplication also listens to requests other than localhost).
If abc.com is just an "alias" you set up in your hosts file then no other person than yourself will be able to use abc.com to connect to 192.168.1.10.20, unless they have the same alias in their hosts file.
If you purchased a domain abc.com and set up it up to redirect to 192.168.10.20 it should work. But usually there are delays associated with updating a DNS so the time it takes for abc.com to be updated can take even a day.
Now if you have your colleagues on a different network (for example they want to connect from their homes when the laptop is connected to the internet at your place) it won't work with a bit of fiddling. Basically, when they try to connect the router gets a request from the client to connect to port 9080, but the router doesn't know what to do with it so nothing happens. You have to set up port forwarding in your routers settings so that all incoming traffic on port 9080 gets sent to 192.168.10.20.
And when they try to connect that way, they can not use the 192.168.10.20 ip adress, because it always refers to a adress on the local network. They have to use your external ip adress (google what is my ip adress).

WiFi server in NodeJS

What I want to do is write software in NodeJS to set up a WiFi server similar to those they use at cafeterias (with WPA2 security or something similar) and guests can connect with credentials or for free on my computer. (I am extra curious as to how I can redirect guests to an html page to enter credentials like they do on some places)
Is there a Node plugin(s) that help with something like this? If not, I am looking for advice like this:
Set up a server on port x and use npm package y and z
Check out this project
More info:
I am creating an intranet for academic purposes.
I have written a dns server in my computer in NodeJS that listens on 192.168.2.2:53 for UDP/TCP and successfully resolves domains in my private network.
My computer is a DHCP client of my Router device which provides access to the internet. Devices at home that use my private DNS server will resolve their dns requests to the internet, only if not found in my private dns.

How to access my IIS server? (Find my ISS IP address)

I just purchased some hardware that requires me to install and run IIS (SQL Express). I did that, and everything went just fine. However, I need to connect the hardware to my computer via WiFi by using the IP address of the computer where ISS is installed on.
I have tried using the IP shown in ipcongig, but it will not connect.
Basically, how to access the server via (a public) IP address.
Also, do I need to keep the computer on all the time in order for it to be accessed from outside?
1.make sure your ip address is static , in order to connect to your computer from outside
and check your iis started or not
2.Yes , you need keep computer on to be accessed

give local node server a name rather then ip address

This might be a stupid question, but i run a business in a strip mall and internet is included (because of this I have no access to the router). the router assigns dynamic ip address and when I set a static ip I lose connection.
is there a way to change the address to my node app from "http:/ /[my-server-ip]:3000" to something like "http:/ /[business-name]:3000". (/ / should be // but stack wont let me post with dead links)
the main reason for this is I have multiple tablets and devices that use this system however recently after they made some changes to the routers setting my computer will be assigned two or three ip addresses a day (I notified the landlord he says its normal). and everytime my ip address changes I lose connection to my app.
is there a possible fix that doesnt require me to host on a web server or enable port forwarding?
perhaps I should reword the question. How do I go about setting up local dns zones from mac? (I know this can be achieved with most linux distros)
No you can't.
Your server IP will always change as the router gives you a new IP address, so change the hosts will not work unless every time the ip on the server changes, you change your ip as well on the devices.
You may try to create an account on dns sites like http://www.noip.com/. They will give you an "external" internet address like mybusiness.noip.com and then you will point your programs on tablets and cell phones to this address.
You will then install a program on your server that will tell noip what the new address is maintaining the same mybusiness.noip.com on them.

Resources