Skip to content

Instantly share code, notes, and snippets.

@feuerrot
Last active January 5, 2016 03:11
Show Gist options
  • Save feuerrot/a6a37e568ce5354eb938 to your computer and use it in GitHub Desktop.
Save feuerrot/a6a37e568ce5354eb938 to your computer and use it in GitHub Desktop.
It may be useful, if you're using dn42 on linux with suitable named interfaces
#!/usr/bin/env sh
echo ' IPv4'
ip r | cut -d' ' -f 5 | grep dn42 |perl -MList::Util=sum -E 'my %cnt; $fmt = "%3d %s\n"; while (<>) { chomp; $cnt{$_}++ }; for my $k (reverse sort { $cnt{$a} <=> $cnt{$b} || -($a cmp $b) } keys %cnt) { printf($fmt, $cnt{$k}, $k) } printf($fmt, sum(values %cnt), "total"); printf($fmt, scalar keys %cnt, "peerings")'
echo
echo ' IPv6'
ip -6 r | cut -d' ' -f 5 | grep dn42 |perl -MList::Util=sum -E 'my %cnt; $fmt = "%3d %s\n"; while (<>) { chomp; $cnt{$_}++ }; for my $k (reverse sort { $cnt{$a} <=> $cnt{$b} || -($a cmp $b) } keys %cnt) { printf($fmt, $cnt{$k}, $k) } printf($fmt, sum(values %cnt), "total"); printf($fmt, scalar keys %cnt, "peerings")'
@sammy8806
Copy link

Here is an counterpart for someone like me who is using FreeBSD and can't really use named interfaces:

#!/usr/bin/env sh
netstat -anr | egrep '(gre|tun)' | awk '{print $2}' | egrep -v '(\#|\%)' | egrep '^[0-9]*[:\.]+' | perl -MList::Util=sum -E 'my %cnt; $fmt = "%3d %s\n"; while (<>) { chomp; $cnt{$_}++ }; for my $k (reverse sort { $cnt{$a} <=> $cnt{$b} } keys %cnt) { printf($fmt, $cnt{$k}, $k) } printf($fmt, sum(values %cnt), "total"); printf($fmt, scalar keys %cnt, "peerings")'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment