Using the IRI API, you can use getNeighbors to get the addresses and then getNodeInfo to obtain the latestSolidSubtangleMilestoneIndex and latestMilestoneIndex.
Only works if the neighbors have open APIs.
cURL examples, courtesy of https://iota.readme.io:
curl http://localhost:14265 \
-X POST \
-H 'Content-Type: application/json' \
-H 'X-IOTA-API-Version: 1' \
-d '{"command": "getNeighbors"}'
returns
{
"duration": 37,
"neighbors": [
{
"address": "/8.8.8.8:14265",
"numberOfAllTransactions": 922,
"numberOfInvalidTransactions": 0,
"numberOfNewTransactions": 92
},
{
"address": "/8.8.8.8:5000",
"numberOfAllTransactions": 925,
"numberOfInvalidTransactions": 0,
"numberOfNewTransactions": 20
}
]
}
Which you can use with
curl [neighbor] \
-X POST \
-H 'Content-Type: application/json' \
-H 'X-IOTA-API-Version: 1' \
-d '{"command": "getNodeInfo"}'
to get
{
"appName": "IRI",
"appVersion": "1.0.8.nu",
"duration": 1,
"jreAvailableProcessors": 4,
"jreFreeMemory": 91707424,
"jreMaxMemory": 1908932608,
"jreTotalMemory": 122683392,
"latestMilestone": "VBVEUQYE99LFWHDZRFKTGFHYGDFEAMAEBGUBTTJRFKHCFBRTXFAJQ9XIUEZQCJOQTZNOOHKUQIKOY9999",
"latestMilestoneIndex": 107,
"latestSolidSubtangleMilestone": "VBVEUQYE99LFWHDZRFKTGFHYGDFEAMAEBGUBTTJRFKHCFBRTXFAJQ9XIUEZQCJOQTZNOOHKUQIKOY9999",
"latestSolidSubtangleMilestoneIndex": 107,
"neighbors": 2,
"packetsQueueSize": 0,
"time": 1477037811737,
"tips": 3,
"transactionsToRequest": 0
}