This is one kind of problem you can write a program to solve instantly. We are counting the number pairs satisfying the conditions you state. First generate the vertices (I'm using Python).
vertices = 
for x in range(1, 13):
for y in range(1, 13):
Next count the pairs satisfying the conditions.
count = 0
for p in pts:
for q in pts:
if p != q:
a, b = p
c, d = q
if abs(a - c) <= 1 and abs(b - d) <= 1:
count = count + 1
Every edge has been counted twice, hence the answer is
count / 2.
There are four types of edges: vertical, horizontal, diagonal (slope 1 and -1). Observe that the number of vertical edges is equal to the number of horizontal edges and the number of slope -1 diagonal edges is equal to the number of slope 1 diagonal edges. So the total number of edges is 2 * #vertical + 2 * #diagonal.
The number of vertical edges is $11\times 12=132$. The number of diagonal edges is $2\times(1+2+\dots+10)+11=121$. $132\times 2 + 121 * 2 = 506$. This can be generalized to a square grid of any size: if the $1\le i,j\le n$, then the number of edges is $$2(n(n-1) + (n-1)(n-2) + (n-1)) = 2(n-1)(2n-1)$$.
Plug $12$ in the formula and you get $506$.