ip address of request from httpheader - c#

I am trying to get the IP address of the request coming in from the httpheader. If value is x do something, if not do somthing else. Can anyone help me out?

Does this help? it seems pretty straight forward.
From the link, there are a few different ways:
HttpContext.Current.Request.UserHostAddress;
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

You might want to look here. The HTTP standards do not define the source address as part of the protocol. Infact HTTP does not directly relate to IPv4 /IPv6 at all.
Generally, a webserver will easily be able to tell the network address of the other end of the socket ( the end where the web browser is ). It does not use HTTP to do this, rather it will use features of the OS's networking stack.
In the case of ASP.NET you should be able to find the IP address where the request came from. You might try looking at System.Web.HttpRequest.UserHostAddress

Related

why do domains like Google have so many IPs?

I am writing some code to retrieve IPs from a domain that comes from a querystring. To achieve this, I have used
Dns.GetHostAddresses(uri);
Which return type is a array of System.Net.IPAddress[]
But I want to write a comment in the code to explain to the developer why a domain such as google for example, may (OK google will) return more than 1 IP address.
Does anyone have a definition or can direct me to a website that has material on this?
Thanks
Its used as a kind of 'load balancer' for DNS queries.
See here for a good discussion:
Is it possible that one domain name has multiple corresponding IP addresses?

Request.IsLocal alternative?

As far as I understand, Request.IsLocal returns true in two scenarios. If the IP address of the request originator is 127.0.0.1, or if the IP address of the request is the same as the server's IP address.
I'm using this on a page which is regularly called by a cron task (using an absolute URL). Unfortunately this cron job is run on the same server as the page, meaning that IsLocal always returns true.
Ideally, I need a function which will just return true if I'm on localhost. How can I do this in a ASP.NET MVC environment?
You could look at the Request.Url property in MVC, but you need to check for 127.0.0.1, localhost and ::1 at least. There's also quite a lot you can do with UrlRewrite if all you want to do is request access. You don't say what you want to do if it returns true/false but assuming that's one of the things you want to do, have a look at UrlRewrite. There's a bunch of useful information in this post too;
How to limit page access only to localhost?

Programmatically distinguish between High Anonymous Proxy, Anonymous Proxy, Transparent Proxy

Suppose I have a proxy IP address, but no infos about it.
Is this possible to know from scratch which kind of proxy it is (distant webservers doesn't know I'm behind a proxy, distant webservers know I'm behind a proxy but doesn't know my IP, distant webservers know both infos)?
Is there a simple test to verify which infos are known about me when I'm navigating?
[edit]
If someone has a simple answer like "no because [etc]", he's welcomed. My first question is "is it feasable".
Lagado Proxy Text mentioned by Joshua Drake in comments works, so it is feasible. The important thing is now to learn how does it work.
Its operation is pretty simple: just be a website. So if you can afford to set up a website which will do exactly the same and will cope with all the traffic you're going to send to it, the problem is solved.
What should such a website do? Check for headers sent by client. The relevant ones are mentioned on the Lagado's page: Via, Forwarded, X-Forwarded-For and Client-ip.
The rest should be easy.
And answering your second question: see BrowserSpy.

Determine if Referring Url is behind a proxy

If you go to whatismyipaddress.com using a public proxy, it will report your proxy ip, but it will also (usually) report that you're using a proxy, and your originating IP as well in many cases.
How does it do this?
Similar sites like Gmail and Craigslist can tell if the computers connecting to them are proxy servers as well.
I have a site with data that is free to browse 200x/day/ip, but I'd like to protect it from harvesting by people using proxies.
Any tips or insights into how this is accomplished are appreciated.
Please check this SO thread. It explains how to do it. It is tagged for PHP but I think the idea remains same here.
**EDIT :**I am duplicating the accepted answer here for reference :
TOR does not supply any server headers
such as X_FORWARDED_FOR, so your best
bet is to use a list of all known exit
nodes. A list can be found at
https://torstat.xenobite.eu/.
For other proxies, you can look at
server headers. Possible server
headers of interest include:
HTTP_VIA
HTTP_X_FORWARDED_FOR
HTTP_FORWARDED_FOR
HTTP_X_FORWARDED
HTTP_FORWARDED
HTTP_CLIENT_IP
HTTP_FORWARDED_FOR_IP
VIA
X_FORWARDED_FOR
FORWARDED_FOR
X_FORWARDED
FORWARDED
CLIENT_IP
FORWARDED_FOR_IP
HTTP_PROXY_CONNECTION
In PHP, you can get the value of these
fields in the $_SERVER[] superglobal.

Custom URI for HTTPListener?

Is there a way to add a custom prefix/URI that is not http or https? The HTTPListener.Prefixes.Add method only accepts http:// and https:// prefixes.
I just don't want to recreate the functionality of this class if I don't have to.
What did you have in mind? Mainly, I doubt it; besides, it will still only handle http[s], so why confuse things with a different scheme name? You can listen on a different port by adding it to the prefix list (eg "http://127.0.0.1:90/"), though. If a client connects on that port using the correct protocol (http vs https) then it would probably work - you'd just have a lot of work to do at the client to tell it how to handle that scheme.
I'm not sure I see a point, to be honest...

Categories

Resources