>>13974244x = x1 + r1 * cos(t), y = y1 + r1 * sin(t)
Where (x-x1)^2 + (y-y1)^2 = r1^2 is the equation of the first circle. Similarly for the second.
This will be important later, but assume that y2 >= y1 (swap the two points if you have to).
For brevity, I will use c = cos(t), s = sin(t).
The slope will just be m = -c/s. Using this info for the equations of the tangent lines, then equating the y-intercepts of the lines, this will give you c*x1 + s*y1 + r1 = c*x2 + s*y2 + r2. Now let X = x2 - x1, Y = y2 - y1, R = r2 - r1. Our previous assumption that y2 >= y1 gives us Y >= 0. Rearranging the equation gives -sY = cX + R.
Square both sides, replace s^2 with 1-c^2, put everything on one side, solve for c using the quadratic formula, then let K = X^2 + Y^2, you get c = (-XR +/- Ysqrt(K-R^2))/K. The choice to have Y >= 0 is what let us factor out the Y from inside the square root.
Now there are two solutions for c, so for each you have two solutions for t, giving you a total of 4 solutions.
Note that if K = 0, this means the two circles have the same center, and they share NO tangents unless R = 0 as well, in which case they share ALL tangents. This is reflected in the formula, where you would get something/0 in the first case, and 0/0 in the second case.