Node.js - Getting the host IP address while on Amazon EC2 - javascript

How can I get the IP address (elastic IP) of the current Node.js host/server on Amazon EC2?
Calling req.connection.address() is useless because EC2 uses an elastic IP. In fact, the IP that shows up using the ifconfig command is not the same as the IP which was used to access the server from outside (which is what I need). How can I get the elastic IP automatically?

From within the instance, you can query for metadata about the instance by sending requests to http://169.254.169.254.
More information can be found here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

You can use DescribeInstances in the API as per the documentation using the filter ip-address to get the public IP of your instance.

Reading about headers and about elastic IP's, I would suggest that headers['REMOTE_ADDR'] gives the address you're looking for (unless behind a load balancer).

Related

Find the private ip of an express server

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
There are a couple possibilities.
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.
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.
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.
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.

Client IP Address in Angular

I need to obtain client local IP address into internal network not the IP over internet by angular for some reason that data will send to IP address over network not based on authorization,I googled so much and I can just find the IP over internet,
Now how can I solve this issue? thanks
Client IP address cannot be accessible by you or with any NPM from front end.
U can find different IP's over internet don't use it.
If you want the client IP, can only be accessed in Node.js.
NPM - request-ip

API Requires Static IP Addresses but I use a CDN

I am looking to use a JSON API that requires that I enter a set of specific IP addresses to allow access to in order to obtain an API key. However, I use a web host that uses a CDN (It should also be noted that I cannot modify any server-side code), so I cannot get a static IP address for my website's server. Is there any way for me to get around this? Is there a way for me make the GET requests to the API through a server with a static IP address that will then relay the request response to the client?
You can setup an reverse proxy on a server with static IP for that (e.g use NGINX). You can easily find some examples on Google like this
The "server with a static IP address" you need is named a reverse-proxy server.
You can install such a server on any cloud Linux or Windows instance: just install Apache according to the following documentation: https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

How to find host original IP from A proxy IP in JAVASCRIPT

I am using a IP location Service. which return location of the Ip. But When some proxy user login My site return wrong address Because the IP is Proxy. How to find out the user using proxy IP and find server Ip From Proxy IP in Javascript
.
While the point of a proxy, as Ryan says, is to block this, in some browsers it is possible to use RTCPeerConnection to get the user's IP.
This is not a perfect solution, and can be blocked fairly easily. Firefox has a built in setting to turn it off, in Chrome uBlock Origin can be used to block it. To check if your browser is vulnerable you can use this page, or take a look at the GitHub Repo.

Web Application using Ember.js and the dynamic ip backend API

I'm playing more and more with Ember and I really like it.
It's new to me but guides are solid and everything.
I understand how to pin-point the API Server IP so Ember can use it, but I would like to make it more dynamic - The idea is that the API Server is on LAN network (or on dynamic IP WAN - but I don't want ddns for that)
The problem is that I currently have to type IP address then deploy and that version work with that one IP address. I would love to be able to type in IP address on first? and then use that ip as the endpoint for api server.
I'm more than sure this is somehow possible but I lack the examples out there.
I understand that there should be application/index.js route that would check some kind of 'store' to check if there is ip address with array that was saved locally in file?/cookie? and if there is one then somehow load that ip to the adapters/application.js host?
Use an initializer if you have to initialize something.

Categories