@JCKline I use a third party adserver (DFP) which is a really complex, powerful and accurate piece of ('free') software to target only the criteria you input - however the WYSIWYG panel and interface make it very simple to use once you get the hang of it.
Server Side Scripts:
If you want to use a server side script to block countries then look in the Apache forum if your server uses Apache etc. They have some excellent advice on this. But this method is best implemented when you want to block your entire site from being seen by country based IP's and Ads as part of your content would only be shown to your white-listed countries.
Now this is used by many publishers who literally only want their content to be seen by certain countries, and they block countries with low ROI or common scrapper countries like Korea etc. - either re-routing them to some other site or showing one Page which states the site is not available in their country. There are also some companies who offer webmasters this service and they do all the blocking of countries on your behalf. However, this method is not so good to implement if all
you want to block are the ads from being shown. Ad Server:
Using an adserver means that all countries continue to see your content and website, but the low ROI countries, and countries with slow internet infrastructure, do not get to see the ads - this means overall lower impressions, higher CTR and less time to serve the page to developing countries. Depending on your niche and audience you get to decide who gets to see what, even altering criteria between different web properties you own.
Use an ad server (recommended). An example of the excellent targeting available on DFP is that a direct advertiser with me only wants their ads shown in the UK, and only once per visitor, on alternate days of the week, between the hours of 8am to 11pm. This is possible with a couple of tweeks to their advertising 'order' and it is done (three minutes tops to set up) ... and yes the ad server does exactly this and keeps track of it all for me.
I put my adsense code through an 'order' in DFP and whitelist it to be seen by only 11 countries, and as competition to some direct advertisers and other ad networks for that 'ad unit'. The only down side to this method is that many of the things DFP needs to know are based on cookie tracking and the inconsistencies of IP addresses, both of these things can throw off the targeting, but on the whole I would say it is above 90% successful. Note:
I am by nature a cautious man, and I have exactly the same set up as I do on google's DFP as I do with the also free to use OpenX system. I use DFP as I like their code and interface but I also made it my business to set up an 'on ramp' account and learn to use the OpenX adserver. If I ever fall out with google (not because of something I do, but because of something that they do) then I can strip out the DFP code from my site, copy and paste in the OpenX code, and I would be up and running direct ads again in 5 minutes flat, with no loss or inconvenience. OpenX has similar functionality to DFP and it is pretty powerful too and I know other people prefer it to DFP ... but I recommend DFP, it really is powerful, flexible and scales incredibly well as your website grows.
[edited by: JoePublisher at 12:04 am (utc) on May 24, 2011]