aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2015-05-04 10:26:40 +0200
committerKristian Lyngstol <kristian@bohemians.org>2015-05-04 10:26:40 +0200
commit0156e238b1b7a6d1c625a3185caa03a6504e7255 (patch)
tree143c87e63767cf772ff0b263be02b5c4b5e0fe60
parent018186eba522de5b96e5583dc9ddbef28da8e245 (diff)
Add dotnet.sh support
Run ./dotnet.sh <ip> <community> and out comes a png with your network topology.
-rwxr-xr-xtools/dotnet.sh4
-rwxr-xr-xtools/draw-neighbors.pl17
2 files changed, 12 insertions, 9 deletions
diff --git a/tools/dotnet.sh b/tools/dotnet.sh
new file mode 100755
index 0000000..ccba503
--- /dev/null
+++ b/tools/dotnet.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+DATE="$(date +%s)"
+./lldpdiscover.pl $1 $2 | ./draw-neighbors.pl | dot -Tpng > ${DATE}.png
diff --git a/tools/draw-neighbors.pl b/tools/draw-neighbors.pl
index a9abc79..16ce551 100755
--- a/tools/draw-neighbors.pl
+++ b/tools/draw-neighbors.pl
@@ -10,11 +10,12 @@ while (<STDIN>) {
my %assets = %{JSON::XS::decode_json($in)};
-print "Drawing family tree from JSON:\n\n";
+print "digraph test {\n";
while (my ($key, $value) = each %assets) {
print_tree ($key,0,undef);
- last;
}
+print "}\n";
+
sub print_tree
{
my ($chassis_id,$indent,$parent,$max) = @_;
@@ -24,13 +25,11 @@ sub print_tree
if ($indent > 50) {
die "Possible loop detected.";
}
- for (my $i = 0; $i < $indent; $i++) {
- print "\t";
- }
- print " - " . $assets{$chassis_id}{sysName} . "\n";
+ print " \"$assets{$chassis_id}{sysName}\" -> {";
+ my @n;
while (my ($key, $value) = each %{$assets{$chassis_id}{neighbors}}) {
- if ($key ne $parent) {
- print_tree($key,$indent+1,$chassis_id);
- }
+ push @n, "\"$assets{$key}{sysName}\"";
}
+ print join(",",@n) . "}\n";
}
+