Last active
August 26, 2018 16:13
-
-
Save spoonincode/6577d30fbaf058ed443864192a56ae70 to your computer and use it in GitHub Desktop.
sort p2p-peer-addresses by ping time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# quick script to sort p2p nodes by RTT (via ping) and output in a format that | |
# can be copy pasta to config.ini | |
# | |
# Usage example: | |
# curl -s 'https://eosnodes.privex.io/?config=1' | listping.pl | |
use Net::Ping; | |
$p = Net::Ping->new("tcp"); | |
$p->port_number(9876); | |
$p->hires(); | |
%found; | |
while(<>) { | |
if(/p2p-peer-address\s*=\s*(([^:]+):(\d+))/) { | |
$p->port_number($3); | |
($ret, $duration, $ip) = $p->ping($2, 1.0); | |
if($ret) { | |
$found{$1} = $duration; | |
} | |
} | |
} | |
foreach my $key (sort { $found{$a} <=> $found{$b} } keys %found) { | |
printf "p2p-peer-address = %-40s # %ims\n", $key, $found{$key}*1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment