You will need depth first search. The algorithm will be:
1) For the current node ask all unvisited adjacent nodes
2) for each of those nodes run depth two check to see if a node at depth 2 is your current node from step one
3) mark current node as visited
4) on make each unvisited adjacent node your current node (1 by 1) and run the same algorithm