#!/bin/bash
show_ip(){
	local output=$1
	ips=()
	interfaces=()
	# echo $output
	while read -r line; do
		ip=$(echo "$line" | awk '{print $2}' | cut -d'/' -f1)
		interface=$(echo "$line" | awk '{print $5}')
		ips+=("$ip")
		interfaces+=("$interface")
	done <<< "$output"
	for i in "${!ips[@]}"; do
		echo "${ips[i]} ${interfaces[i]}"
	done

}

filename="output/output_$(date +'%m-%d_%H-%M-%S').txt"
echo $(date +'%m-%d_%H-%M-%S') 
echo ' ' > $filename

ip_cmd='ip address show | grep 10.5'
for num in {1..4}
do
	echo "router$num" >> $filename
	echo "router$num" 
	ip_output=$(ssh router$num $ip_cmd) 
	ips=()
	interfaces=()

	result=$(show_ip "$ip_output")
	echo $result
	echo $result >> $filename

	
done

for num in {1..3}
do
	echo "pc$num" >> $filename
	echo "pc$num" 
	pc_result=$(ssh pc$num $ip_cmd)
	result=$(show_ip "$pc_result")
	echo $result >> $filename
	echo $result
done

