How to get client IP in 3-tier architecture? - asp.net

I am currently working on module which has the following architecture:
When a client makes a request it is forwarded to a node server which has a ELB in front of it. The node server gets the data from backend .NET code hosted in another server with a different call.
Is it possible to access the client IP in the backend code written in .NET considering this architecture?

you can get ip in node
In your request object there is a property called connection, which is a net.Socket object. The net.Socket object has a property remoteAddress but it may be possible ip server is behind proxy server so try the below code to get IP
request.headers['x-forwarded-for']
Check the below Stack Link for more answers
How to determine a user's IP address in node

Related

'Invalid hostname' response from http.sys

We have web service running hosted on an OwinHttpListener (http.sys behind the scenes). Whenever we send requests to the app on the IP address, it responds with 'Invalid hostname'.
After much trawling of stack overflow and google, im not really any closer to a solution. The requests are getting through to http.sys, as i can see them in the HTTP error log. I can log onto the server in question and access the service locally (using localhost or 127.0.0.1) and i can use the server name to successfully get through, the only failure condition is using the servers IP address.
Ive tried the following:
Ensure the app is listening on all interfaces (http://+:8080)
Ensure IIS is not trying to use the port (it isnt)
Ensure windows firewall is configured to allow traffic on that port (it is)

IP address issue when deployed in Server

I have a Servlet project developed using Tomcat 7.
My projects logic is that whenever a request comes from certain IP it responds to the same IP with a new instance of browser as an response.
When I run and test this application locally it works perfect and by the way my local working IP address will be something like this 10.52.xxx.xxx. So request has 10.52.xxx.xxx and response is given to 10.52.xxx.xxx and all happies
Now things looks perfect and I planned to deploy this project in a Server which has an IP addess of 172.32.xxx.xxx and I have completed deployment of the same.
Now the issue which I am facing is that when I try to make a request to the project in the server (172.32.xxx.xxx) from my network (10.52.xxx.xxx).
In my project I have code like
String ip = request.getRemoteAddr(); //gets request IP address to give a new instance of browser
Now the variable ip contains an IP address of 172.32.xxx.xxx. So my code will try to give a browser instance to 172.32.xxx.xxx which doesn't exist. It should ideally give the browser instance back to 10.52.xxx.xxx as this is from which it had received the request so it has to respond to this IP.
I know both Server and the client request are in different IP network but I would like to know all possible solutions to fix the same so that browser is given back to 10.52.xxx.xxx.
Any help highly appreciated.

Connecting to remote Glassfish hosted EJB

The application i'm currently working on start to enter in a pre-release phase.
In this phase, the server-side application components are to be deployed on Amazon VMs while the client-side application remains on the user machine.
This applications connects to server using JNDI and RMI to call remote EJB methods. This works well on localhost and local network.
But, when trying to connect to Amazon host, the application hangs up on context.lookup method. that's to say a JNDI context can be obtained from this remote server, but no lookup can be performed on that context.
What can I do to obtain good diagnostic on the failure ?
Are there logs that can be generated for the RMI handshake/whatever ?
Is there any way to see on server side if query really drive its way through the internet to the server ?
Also notice I've already enabled public IP usage on my Glassfish server (using recommended Oracle procedure).
EDIT According to a fast TCP capture on server, it seems that server receives the client context query with in-lan client address, which it of course isn't aware of :
query is
[3/27/2012 11:05:22 AM:169]
GIOP.......(................NameService....._is_a...................
NEO................ª.......(IDL:omg.org/SendingContext/CodeBase:1.0.
...........n........172.27.63.145.ܺ....¯«Ë........e................
........... ................... ... ...........&...............(IDL:
omg.org/CosNaming/NamingContext:1.0.
reply is
[3/27/2012 11:05:22 AM:171]
GIOP.......2............NEO................0.......(IDL:omg.org/Send
ingContext/CodeBase:1.0............ô........46.137.114.67.'5....¯
«Ë........d........................... ................... .........
.....&...........!...|...............$....f............10.241.42.208
.'6.#........g..............g........default...................g....
...........+IDL:omg.org/CosNaming/NamingContextExt:1.0..............
.......10.241.42.208.'5...M¯«Ë.... ...d... S1AS-ORB............Root
POA....TNameService............................... .................
.. ... ...........&......
(as read using SmartSniff ASCII output).
The IP in query (172.27.63.145) is my IP in my company LAN. From what I understand of communication over itnernet, it should be my company LAN public IP, no ? How can I make Glassfish client udnerstand it should use that IP ?
Diagnostic has been clearly obtained : the client, which connects from a LAN to the server, sends its own internal network private address to server, which server can't forward any answer to. As a consequence, server doesn't answer, hence the hangup.

Getting An IP Address in a CSLA remote data portal

I'm writing an app in CSLA and want to log IP addresses, but only if the client is calling a remote data portal (such as the WCF one).
How can I get the client's IP address when executing within a remote data portal? I realize I could probably pass it with the request, but I'd like to avoid this if possible.
CSLA .NET forum thread on this topic

How can I get the Url of the web site which is using my web service?

I have developed a web service and host it on my server and I would like to know who is using this web service (site Url). I tryed to use "Request.UrlReferrer" but it is not returning any thing! any suggestions/Advices?
You can't get the URL of the caller of a web service as not all callers have canonical URL's. You can however get the IP Addresses assuming that they are not behind a proxy / nat. In which case you'd get the IP of the nat / proxy.
Assuming your using an ASMX web service you can this from:
HttpContext.Current.Request.UserHostAddress
Once you have the IP Address you can try and do a reverse lookup to get the host name. I would recommend storing the IP address then writting an offline process which goes and tries to determine who owns the IP. I'm sure there are some webservices out there to help with this.
You can use Request.Url property to get all the information about the requests to your web service.
The referrer is set by the client, and the client can not set it. That is why you see nothing. If the client's are servers, then the best you can do is to get the IP of the client connection and go to that IP. If a simple setup, with no virtual hosts, then that is the "web site" that is hitting your web service.
As Josh states, the HttpRequest object is the way to go, there are a few properties on there that might help:
UserHostName - Gets the DNS name of the remote client.
UserAgent - Gets the raw user agent string of the client browser.
UserHostAddress - Gets the IP host address of the remote client.
Which might give you a bit more information to play with.

Resources