First you can create a database of country boundaries. Country boundaries are easy to find online. Here is one source: http://www.diva-gis.org/Data
You can upload these into SQL 2008/2012 or Azure (express version is free) using the Shp2Sql tool here: http://www.sharpgis.net/page/Shape2SQL.aspx
Then using Bing Maps you can calculate a route and get the route point's. You can use the route points to create a LineString object and do an intersection test against the country data to get all the countries boundaries that line passes through. Then you can go through each resulting country and crop the line to the borders of the country. With the crop line you can then measure it's length. All of this can be done with the spatial tools in SQL. Here are some useful links.
http://msdn.microsoft.com/en-us/library/ff701713.aspx
http://technet.microsoft.com/en-us/library/bb933901.aspx
http://technet.microsoft.com/en-us/library/bb933962.aspx
http://technet.microsoft.com/en-us/library/bb933895.aspx