I am using the ip library of npm.
I have two config files, one for React and one for Node, for the same application.
const ip = require('ip');
console.log(ip.address());
This returns different ip addresses for the React config file(inside the src folder-127.0.0.1) and Node server file(outside the src folder - IPv4 address).
The issue is that I am pretty sure that I ran the exact same code earlier and it gave me the same ip addresses for both as then I was able to access my webpages. I need the same ip to make requests to my node backend, I cannot afford it in production. Are there other definite methods of doing this?
You get different ip results because 2 method call ip.address() are using different network interfaces.
To make ip.address() return identical result, you can pass network interface name as the first parameter, such as en0:
const ip = require('ip');
console.log(ip.address('en0'));
p.s. To get all current networks interface names, os.networkInterfaces() can be used.
Update: OP try to get IP address in React code, in browser side. This is mission impossible. Otherwise, it would bring huge security problem.
Update 2: OP don't want to store endpoint IP address in frontend code for security reason, neither want to retrieve the IP address first (network overhead issue). In this case, you can make a proxy in server. All frontend know is interacting with current server, the data exchange is delivered by server as:
Browser <--> Server <--> Various endpoint IP
The steps are:
The server (that host the frontend code) get request from browser
Server check which endpoint would be used for that client
Server send the request to specific endpoint
Server get response from endpoint
Server return the response in above step to browser
Related
So, I have a express API that checks a list of blocked IPs, if the request IP matches one IP on the IPs blocked list, I want to sent a message to the end-user.
Now I'm implementing tests, I have been using supertest to make calls to my API endpoints
Let's say I want to make two calls the endpoint "/user":
one call with IP 127.0.0.1 (default)
one call with IP 127.0.1.1 (API should block this IP)
I found some old stackoverflow issues, did everything as shown in the answers, but none answers changed the supertest IP, therefore my API didn't return a message saying the IP was blocked
So, is there a way to automatically test IP bans?
I am trying to make a GET request to a foreign server. But the foreign server requires our IP address for security purposes.
Now the problem is I am running my app inside Kubernetes' pod with three nodes.
When I send the request, it takes the IP address of one of the kubernetes nodes.
I could add static IP addresses to all my nodes. But from what I have learned, best practice is to only release the Gateway(ingress) IP address to the outside world. Everything else should be hidden.
So I tried to proxy my axios request like this:
var res = await axios.get('https://someapi.com', {
proxy: {
host: 'ingressIP', //static ip
port: 80
}
});
But the request still returns an error saying that the IP is not allowed. It returned the IP address of the kubernetes node, where my POD was in.
I am not sure, that you will be able to pass your traffic through ingress somehow.
We also had the same problem. We needed to send requests to a third-party server from a specific IP-address.
But we solved this a bit different, we just created a new small server with static IP, installed Squid proxy server there and configured our applications to use Squid server as an HTTP forward proxy.
Squid has a lot of features, and IMO is quite bloated for such a simple use-case; I'd suggest something more lightweight, like tinyproxy (docker image here). So what you can do is create a Deployment using that image, pin it to a specific node (the one with the IP that the 3rd party API allows) using nodeSelector, create a Service pointing to it, and use that as a proxy in your requests. There's one drawback to this approach, though - you just added a(nother) single point of failure to your infrastructure.
I deployed my .NET CORE solution in AZURE environment (PAAS).I used following code snippet there to get client's ip address
dtoItem.LogIP = HttpContext.Connection.RemoteIpAddress.ToString();
I used standard .net core libraries and did necessary changes into Startup.cs as well
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
RequireHeaderSymmetry = false,
});
I believe I have implemented everything in correct manner. But still I haven't got accurate client IP address. I am always getting client's public IP instead of his private IP. Since this can be repeated (Same office 2 users have same public IP) I need client's private IP instead of his public IP.
Is it possible to get private IP address in PAAS solution. If it is not possible, is there a way to track client's PC information. (Such as IP Address, MAC address).
Is it possible to get private IP address in PAAS solution?
No it is not possible as shared in this SO post and this answer address this about MACAddress
On the client side javascript, there is no API exposed to get the IPAddress(obviously due to security consideration) .Then you can get the IPAddress on the server side but typically if you are accessing internet from your company,it would go through the corporate proxy and the Ipaddress seen by the server will never be the actual client IP but the proxy server's address. So this is limited on the server side as server only sees the proxy (public IP address).
If it is not possible, is there a way to track client's PC information. (Such as IP Address, MAC address) ?
What you can reliably track is the user agent. Breaking the user agent down, we get the some information about browser ,OS versions. But user agent can easily be spoofed with some browser extension .
If you are looking for browser finger printing or tracking ,have a
look at Panopticlick which shows some more information like
fonts > installed, screen resolution,plugins installed etc to track
any client. fingerprintjs2 javascript library helps to track
using 26 parameters as of today
There is no straight forward answer to this. The thread shared by Rob has some great insights. However, one needs to understand that a lot can happen to the request before it reaches the server. The intermediary networking devices can manipulate the TCP headers so it may not reflect the correct IP Address that you need.
From a solution perspective, this might be perfectly possible, if you develop your own client and log this information somewhere so that you can track it. Otherwise there is no reliable way to get this information.
I'm working on a system with three parts that communicate over HTTP. The parts are the Service, the ServiceRegistry, and the Client. The Service and the ServiceRegistry are self-hosted OWIN applications. The nature of the client doesn't matter.
In my design, the Service POSTs to the ServiceRegistry to "register" itself. The ServiceRegistry reads Request.GetOwinContext().Request.RemoteIpAddress to determine where the Service is located and GETs back to the Service to perform some handshaking (the port for this GET is supplied in the original POST). Finally, the Client comes along and performs a GET to the ServiceRegistry asking for the location of the Service and receives back the IP address and port on which it can directly interact with the Service.
This works well when all three parts are running on different machines.
However, when the configuration is that the Service and the ServiceManager are running on MACHINE01 and the Client is running on MACHINE02 the system fails. What appears to be happening is (when both parts are located on one machine) RemoteIpAddress receives a link-local version of the IPV6 address. I strip off the Scope ID from the IPV6 address and return the address and port to the Client. But, to the Client running on a different machine, this is an unreachable address.
Can anybody suggest how I can read the remote IP address from the OWIN request in such a way that it will be reachable from another machine on my network?
When you are connected with any address, I don't think there is a way to get other addresses of the peer.
You could either implement and use some registry of address mappings between link locale addresses and global addresses. (Always in the hope the peer accepts requests on its global address as well.)
Or if you have access to it I'd propose to modify the requesting peer to send the request originating from its global address. This can normally achieved with source address selection. But I have no idea how you do this on the .NET platform as I am working on Unix systems.
I am building a complex SPA using Polymer to replicate an Access Application. I want to use http2 to avoid the maintenance nightmare of merging source files to get appropriate performance.
I have built myself the start of the application, log in via a sql server database. and am now starting to debug things.
I am trying to retrieve the clientip address using answers I have found on here
var ip = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
but unfortunately at this point the server crashes. Digging around with the debugger (given req is the request object) there is no 'x-forwarded-for'header, no connection object (except inside socket) and this is what kills this statement as can't access remoteAddress of undefined. But I cannot find a remoteaddress field in any object derived from req.
I am using https://github.com/molnarg/node-http2 which appears to be the only implementation around. There is some mention of endpoint.js library in the documentation but the links are broken, so I have no idea how to access an endpoint object.
In order to get the correct certificates, I am using the ones from pastrial.hartley-consultants.com and changed my in house dns server to give me my development machine as its ip address. I am accessing it via a browser on the same machine. So client and server machines should both have 192.168.0.xx IP addresses which just happen to be the same.
So question is - where is the IP address of the client exposed to the server (or indeed is it in http2)
The simple answer is it is in req.remoteAddress