aboutsummaryrefslogtreecommitdiffstats
path: root/tools/make-linknet-hosts.pl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/make-linknet-hosts.pl')
-rwxr-xr-xtools/make-linknet-hosts.pl34
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/make-linknet-hosts.pl b/tools/make-linknet-hosts.pl
new file mode 100755
index 0000000..d535832
--- /dev/null
+++ b/tools/make-linknet-hosts.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use NetAddr::IP;
+use Net::IP;
+#
+# Input file format:
+#
+# ipv4-link-network router1 router2
+#
+# e.g.
+# 151.216.0.2 telegw nocgw
+# 151.216.0.4 telegw cam
+# 151.216.0.6 nocgw coren
+# 151.216.0.8 telegw pressegw
+#
+# Note: IPv6 linknets use link-local adresses, so they are not included in list.
+#
+while (<STDIN>) {
+ next if /^(#|\s+$)/; # skip if comment, or blank line
+
+ my ($ipv4_raw, $from, $to) = split;
+ my $ipv4;
+
+ # Assumes ipv4 address is the first address in a /31 :-))
+ $ipv4 = NetAddr::IP->new($ipv4_raw."/31") unless $ipv4=~/no/;
+ printf STDERR "Missing IPv4 scope for linket %s -> %s\n", $from, $to if not $ipv4;
+ next if not $ipv4;
+
+
+ # generate-dnsrr.pl format:
+ # hostname ipv4 ipv6 (with nope as valid null argument)
+ my $ipv4_other = $ipv4 +1;
+ printf("%s-%s %s nope\n", $from, $to, $ipv4->addr);
+ printf("%s-%s %s nope\n", $to, $from, $ipv4_other->addr);
+}