1

I have a website and i need to deploy it in a single country for example Lebanon. In other words, any request that comes to the website from any other country should not be responded to.

I think I may use the IP address of the request and know from which country it was generated. How can I do this in C#.

Ghyath Serhal
  • 7,466
  • 6
  • 44
  • 60
  • 3
    This is bound for failure. Also a dupe/related: http://stackoverflow.com/questions/2111246/how-to-limit-web-site-access-to-usa-or-north-america-only – Grant Thomas Apr 15 '11 at 12:12
  • Some users may use proxy in Lebanon which has IP in a range that indicates they are somewhere else. Why would you like to restrict it? Even you if you travel abroad, want to have access to your website, don't you? – Lukasz Madon Apr 15 '11 at 12:20
  • As this is nearly impossible to achieve, you could write all your website only in Lebanon dialects which won't prevent other countries to connect but kind of deterrent force :-) – hornetbzz May 20 '11 at 19:55

2 Answers2

5

I think I may use the IP address of the request and know from which country it was generated

No, you dont. Illusion.

  • you can not know which country a request comes frmo, only where the IP address is registere, pretty much. More information is avaialble parsing the reverse dns SOMETIMES if you are smart at this.
  • This ignores little issuesl ike large international providers that may use a central pool of addresses, like VPN providers etc. Or satellite phone providers (which may be used out of a country but not be resident there).

At the end this will be of RELATIVELY limtied use, depending what your exact busienss case is it may be totally useless.

How can I do this in C#.

Programming.

Get a GeoIP database (look up the term in google, a provider will show up, otherwise try it in combination with "maxmind"). THen query the IP against the database. Decide how to handle "maybe" scenarios like international businesses. Example... IBM has address space. They use it for all their oprations. How you want to deal with this?

TomTom
  • 61,059
  • 10
  • 88
  • 148
  • Also consider the inverse. An Lebanease user with a non Lebanon IP, perhaps they are protecting thier identity with a secure VPN Provider. The shop of the www.o2.co.uk site does it, it doesent work in many cases. – Jodrell Apr 15 '11 at 12:18
  • Even simpler. My office (Poland) runs all traffic through the company VPN to the company cluster in Germany, from there to the internet;) Easier to maintain one firewall. Ergo... my IP is no where I am. – TomTom Apr 15 '11 at 12:26
0

One thing you can do to encourage local indexing and participation is deploy your website with a Lebanon country code suffix.

www.example.co.lb

Here's a list of country suffix domains.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111