We're writing an ASP.NET 5 (vNext) application that partly includes geocoding the user's location based on their IP address. We're attempting to grab the client's IP address using the following code found from a number of examples across the web:
var connection = context.HttpContext.GetFeature<IHttpConnectionFeature>();
if (connection != null) {
clientIpAddress = connection.RemoteIpAddress.ToString();
}
When we log the clientIpAddress that comes from the IHttpConnectionFeature, we find that the IP address is not correct.
However, we do notice that IIS is capturing the correct client IP address. We see this by inspecting the requests via the IIS control panel.
So, somewhere between the IIS request and our application code, the client's IP address is being modified, or our application code is not working properly with IIS. Or is it possible that IIS is performing extra work in deciphering the client's IP address - work that we need to mimic in our application code.
Why is the client's IP address correct in the IIS request logs, but not correct in our application code above? How do we grab the correct client IP address in our code?
Relevant software versions:
ASP.NET 5 (vNext)
KRE 1.0.0-beta2
IIS 8
Update: We ran a .NET 4.5 application on the same IIS server that retrieves the IP address using Request.UserHostAddress and it also retrieved the correct IP (the same one IIS is logging), so it seems to be an issue with the new .NET 5 code.
This was due to a bug in the Microsoft.AspNet.Loader.IIS package. Luckily, the guys at Microsoft speedily posted a fix.
For more context, see the Github issue: https://github.com/aspnet/HttpAbstractions/issues/181
Related
So, this problem has recently cropped up. I have an application that has been running for many years. The application is a RAD Studio C++ based web server application. In the application, I check the client's IP Address via Request->RemoteAddr. Suddenly (could be from a MS update) the RemoteAddr value is now the server's IP address instead of the client.
Is there a work-around or a fix for this?
I am new to configuring apache webserver(this is my first time) and over the last few days i have been trying to configure apache so as to view the default page over the internet.I have been successful partially in being able to view the default page over local host on the network. The problem really comes over when I try to view the page over the public ip of the server.Every time i try the page reports a time out and/or an error in connection, so I have increased the time out from 300 to 3000(the issue remains). I have searched extensively over the internet and based on the findings i have configured apache to grant all connections, i have also configured the firewall on my linux system to allow incoming & outgoing. Further I have configured my dad's huawei hotspot e55** series as mentioned in the link here https://portforward.com/huawei/ . I have also tried to configure my internet connection for port forward from external to the internal ip however what i observe is that after i do that my internet connection seems to get disabled and I would have to delete the connection and add another one.At this point it looks like that I might be missing out something here and I believe a little help from the apache experts might just help me achieve my goal to view the default apache web page over the web using the system (public)ip(using whatismyip on google search).
I think the public ip provided by your ISP cannot be used for hosting the website on the internet please contact your ISP to get a public IP that can host websites over the internet , or get a cloud hosting server.
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 have tried to send a DNS packet to get an IP of some web-site.
In some cases, like google, the IP was right and when i typed it in the url line it sent me to google.
But in other cases (for example : stackoverflow.com) its gave me an IP that didin't linked to the web-site.
To be sure that my packet is right, i tried to do Nslookap in the command line, and the result was the same.
So i cant find the right IP adress of a web-site.
There is the message that appear when I'm trying to enter stakoverflow
Fastly error: unknown domain: 151.101.65.69.
Please check that this domain has been added to a service.
You (generally speaking) can not open the website just by entering the IP address in your browser's address bar because web servers (and possibly many other network components that are between you and the web server) often do not host only one web site on that IP address so they rely on exact domain name typed in address bar to serve the right content.
I think, it's caused by yours internet restriction. Try to contact your ISP (your internet provider) about this problem. He will probably know more about cause of this problem.
Short answer: you need a host header.
Long answer: Since HTTP/1.1 introduced in 1997 (and then updated in 1999 and in 2014), the request needs a host header. That allows the web server to route a request to a corresponding server configuration, a virtual server in Apache speak. Some servers don't have this configured and is allowing requests to any host to be served from the same web server configuration.
HTTP/1.1 also allowed multi-tenant proxies, as Fastly, to exist in the Internet. Fastly is a CDN - content delivery network - that allows to cache websites content on closer to users and deliver it locally (faster than from a cloud or a colo, thus the name).
When you're not specifying the domain for the request, it looks like your client (or a library) is using the IP address as the host header. That's why the response from Fastly talks about domain: unknown domain: 151.101.65.69.
While Fastly do support service pinning to a dedicated IP address, which would have worked for your request - it doesn't look like stackoverflow is using the feature as they might not need it.
After 4 hours of looking through stack overflow and searching Google I've finally decided to go check in with the "hopefully" gurus...
My problem is this, when querying from the local machine through remote desktop, querying for www.domainname.com/Content/Styles/reset.css i get the css fine.
When doing the same from an external machine, I get a 404 error... I know why, the reason is that it's trying to get the file from:
C:\inetpub\wwwroot\Content\Styles\reset.css
This is kind of bad considering that the website is actually hosted at: c:\http\www.domainname.com\
The error in the browser, from IIS, gives the following information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://www.domainname.com:80/Content/Styles/reset.css
Physical Path C:\inetpub\wwwroot\Content\Styles\reset.css
Logon Method Anonymous
Logon User Anonymous
I've been looking at the other sites running on the IIS, and none of them point to InetPub as their directory, so I simply can't see why it's trying to get the item from this path.
Calling the main application, a MVC based site running Umbraco, works fine, or rather, all the dynamic content works fine, just not static content.
To give a little more information:
Currently the IIS 7.5 has 4 sites and 1 ftp server running.
1 site with the following bindings:
http - this 1st site host name - port 80 - ip address *
https - blank host name - port 443 - ip address *
1 site with the following bindings:
http - the 2nd site host name - port 80 - ip address *
1 domain with the following bindings:
http - the 3rd site host name - port 80 - ip address *
The actual domain
http - www.domainname.com - port 80 - ip address *
And finally a ftp server
I hope that someone have any idea what is going on...
Best regards and praying (despite being an atheist),
Poul
Could it be that the Static File Handler is not included for your website?
Check for your website if the Handler Mappings contains Static File as Handler. ( preferrably at the bottom of the list)
Update:
Is there a physical folder under wwwroot called content\styles? or a folder www.domainname.com for that matter?
Did you look at logs from IIS for the application pool of this website
--> C:\inetpub\logs\LogFiles\W3SVCxx (xx = number assigned to your app pool) I forgot how to find that on ( usually I quickly check the couple of folders here.
Maybe it's a security problem -> do you see events in the security eventlogger.
So I found the problem...
It turns out to be a Proxy issue... As this is a new site, the DNS wasn't set up yet and we were using the HOSTS file.
Unfortunately in Bangkok when using a Cable connection, True (the largest ISP) forces you to use a Proxy, without telling you...
Now the DNS was actually pointing to another IIS server...
When I made my request, asking for a file on domain name X.. My machine looked up the IP address through my HOSTS file, sent the request, the proxy then also did a DNS lookup, but got another IP address, and forwarded the request to this IP address instead.
The IIS on that server, knew the IP, knew the domain name, but had another configuration and didn't know the file we were asking for (for the new website)...
So indeed there is a logical explanation for everything, just not always an obvious one.
I actually got onto the problem by testing with another domain, one that didn't exist at all, on this one the proxy of course could not look it up, and started returning code 324.