Skip to content

Commit

Permalink
Merge branch 'cupivan' of https://github.com/CupIvan/cjdns into crashey
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdelisle committed May 2, 2019
2 parents 40c6357 + 82de42c commit e32175c
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions contrib/php/getBrokenPeers
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env php
<?php
/**
* Ping public peers from github and show broken peers
*/

// clone or update peers repo
if (file_exists('peers'))
passthru('cd peers; git pull > /dev/null; cd ..');
else
passthru('git clone "https://github.com/hyperboria/peers.git" > /dev/null');

// get peers and ping it
require_once 'publicKey2ipv6.php';
$data = json_decode(@file_get_contents(FNAME), true);
if (!$data) $data = [];

printf("%-15s | %4s | %5s | %4s | %s
--------------- | ---- | ----- | ---- | -----\n", 'IPv4', 'ping', 'IPv6', 'ping', 'url');
foreach(get_files('peers') as $fname)
{
$st = file_get_contents($fname);
parse($st, $fname);
}

function get_files($dir)
{
ob_start();
passthru("find $dir | grep '\.k'");
$st = ob_get_clean();
return explode("\n", trim($st));
}

function parse($st, $fname)
{
global $data;
$a = json_decode($st, true);
foreach ($a as $k => $a)
if (strpos($k, '[') === false)
{
$st = '';

$ip = explode(':', $k)[0];
$st .= sprintf("%-15s", $ip);
exec("ping -c3 -W5 $ip", $out, $res);
$st .= sprintf(" | %4s", $res ? 'FAIL' : 'OK');

$ip = publicKey2ipv6($a['publicKey']); $x = explode(':', $ip);
$st .= sprintf(" | %5s", ':'.$x[count($x)-1]);
exec("ping -c3 -6 -W5 $ip", $out, $res);
$st .= sprintf(" | %4s", $res ? 'FAIL' : 'OK');

$x = str_replace('peers/', '', $fname);
$x = "[$x](https://github.com/hyperboria/peers/blob/master/$x)";
$st .= ' | '.$x;
$st .= "\n";

if (strpos($st, 'FAIL')) echo $st;
}
}

0 comments on commit e32175c

Please sign in to comment.