#!/usr/bin/perl
use strict;
use feature qw(switch);

# This script returns the IP address of the matching service node on the other system.
# For example, running this script from a node with an external IP address of
# 192.58.3.38 would print the string "192.58.4.38".

my %other_system_prefixes = (
    '192.58.1' => '192.58.2',
    '192.58.2' => '192.58.1',
    '192.58.3' => '140.90.226',
    '140.90.226' => '192.58.3',
    '192.58.154' => '192.58.153',
    '192.58.153' => '192.58.154'
);
#my ($current_system_prefix, $node_num);

foreach (`/sbin/ip address`) {
    if (/inet ((?:192\.58|140\.90)\.\d{1,3})\.(\d{1,3})/) {
        #$current_system_prefix=$1
        #$node_num=$2;
        if (exists $other_system_prefixes{$1}) {
            print $other_system_prefixes{$1} . "." . $2;
            exit;
        }
    }
}

die "Could not find IP of the matching node on the other system\n";

