We propose a transfer matrix algorithm for the enumeration of alternating link diagrams with external legs, giving a weight $n$ to each connected component. Considering more general tetravalent diagrams with self-intersections and tangencies allows us to treat topological (flype) equivalences. This is done by means of a finite renormalization scheme for an associated matrix model. We give results, expressed as polynomials in $n$, for the various generating functions up to order 19 (link diagrams), 15 (prime alternating tangles) and 11 (6-legged links) intersections. The limit $n\to\infty$ is solved explicitly. We then analyze the large-order asymptotics of the generating functions. For $0\le n \le 2$ good agreement is found with a conjecture for the critical exponent, based on the KPZ relation.