Geo IP (CF-IPCountry) only works for US ip addresses

This only returns a value (“US”) for IP addresses originating in the US. It returns nothing when registration bots hit my site from overseas.

Request.Headers[“CF-IPCountry”].ToString();

That is the right header and that header does contain all countries. Where did you take this code from?

That is how I get a header from the Request in ASP.net

So you are having an ASP.NET application behind Cloudflare?

I guess your code should work then. Are you sure these non-US requests come via Cloudflare? Do you have a public URL to test it?

Correct, ASP.NET application on Cloudflare.

This site is being swamped by a registration bot, started using firewall rules to block countries based on the IP capture during registration.
Using Request.ServerVariables[“HTTP_X_FORWARDED_FOR”]; to determine the country.

Blocked 30 or so countries which cut back some of it, but there are still plenty of registration attempts, so I started to use CF_IPCountry to see if it would get be a better indication of the originating country.

I am testing this myself by creating a registration on my site, so I can see if it works and it does. But I am in the US, the bot is not in the US and not in the list of excluded countries.

Are you sure these non-US requests come via Cloudflare?
Isn’t all this traffic coming through Cloudflare?

Not necessarily. Check the original IP address for that. Also, check if you have all Cloudflare headers in cases you seem to miss the country information.

How do I check the original IP address?

How do I find the cloudflare headers?

The Cloudflare headers are all part of the HTTP request headers. The original IP address is the connecting one (not the client address provided by Cloudflare in the header as well).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.