From 89c500e47184a2be18a7596057d277cf2fa4ab62 Mon Sep 17 00:00:00 2001 From: Robert Langhammer Date: Mon, 11 Oct 2021 23:06:04 +0200 Subject: [PATCH] Init commit --- fastd-status.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 fastd-status.pl diff --git a/fastd-status.pl b/fastd-status.pl new file mode 100755 index 0000000..593480e --- /dev/null +++ b/fastd-status.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -w + +use strict; +use Switch; +use IO::Socket::UNIX qw( SOCK_STREAM ); +use JSON::XS; +use Data::Dumper; +$Data::Dumper::Indent = 1; +$Data::Dumper::Terse = 1; + + +$ARGV[0] or die("Usage: fastd-status.pl [ips|keys|json]\n"); + +my $socket = IO::Socket::UNIX->new( + Type => SOCK_STREAM, + Peer => $ARGV[0], +) + or die("Can't connect to server: $!\n"); + +my $json_array = decode_json (<$socket>); + +if( defined $ARGV[1] ) { +switch ($ARGV[1]) { + case "ips" { + foreach my $fastdkey (keys %{ $json_array->{peers} }) { + print $json_array->{peers}->{$fastdkey}->{address}; + print "\n"; + } + } + case "keys" { + foreach my $fastdkey (keys %{ $json_array->{peers} }) { + print $fastdkey; + print "\n"; + } + } + case "json" { + print Dumper $json_array; + } + } +} else { + my $i = 1; + foreach my $fastdkey (keys %{ $json_array->{peers} }) { + print "peer $i\n"; + print "address: $json_array->{peers}->{$fastdkey}->{address}\n"; + print "fastdkey: $fastdkey\n"; + print "mac: $json_array->{peers}->{$fastdkey}->{connection}->{mac_addresses}->[0]\n"; + $i++; + } +} + +