Taurus Omejia
Taurus Omejia

Reputation: 57

How can I Block an entire country's IP in web.config

Is it possible to block an entire country's IP with web.config, for an ASP.NET site? I figured out how to block an individual IP, but after researching I can't seem to find the right solution to block an entire country.

Upvotes: 1

Views: 3399

Answers (3)

Lews Therin
Lews Therin

Reputation: 3777

As others have mentioned, you cannot block a "country" from the webconfig, but you can block the IP range for that country using subnetmask.

Relevant code:

<!--block network 83.116.119.0 to 83.116.119.255-->
<add ipAddress="83.116.119.0" subnetMask="255.255.255.0"/>

Upvotes: 1

Akshay Gupta
Akshay Gupta

Reputation: 361

You can use Maxmind GeoIP database to search for a country's IP addresses..https://www.maxmind.com

The database is quite accurate when compared to other Free services.

Upvotes: 2

Benjamin Abt
Benjamin Abt

Reputation: 1838

You cannot block a country, but you can block IP ranges. This approach is used in the most "Country block" scenarios.

Since IIS6 you can block IP and IP-Ranges with the IPSecurity element.

But this is very inaccurate because an IP addresses have no fixed mapping to a country, or could be filtered by services like CloudFlare. And also dynamic IP geolocation is working but is often not precise.

Upvotes: 1

Related Questions