summaryrefslogtreecommitdiff
path: root/misc/ssh-rt.sh
blob: b26e2aa852e2a098c231218530c659f7feb98d2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
echo "$@" | awk --non-decimal-data '
BEGIN { iface="eth1"; exitcode=1; }

/^172\./ {
	print "L IPv6 de management des routeurs n est pas fonction de L IPv4 en 172";
}

/^185\.131\.4([01])\.([0-9]{1,3})$/ {
	match($0, /^185\.131\.4([01])\.([0-9]{1,3})$/, arr);
	printf "ssh root@fe80::%x:%x%%%s\n", arr[1], lshift(arr[2],8), iface;
	exitcode=0;
}

/^2a03:a0a0:([0-9a-f]{0,4}:[0-9a-f]{0,4}):?:?.*$/ {
	match($0, /^2a03:a0a0:([0-9a-f]{0,4}:[0-9a-f]{0,4}):?:?.*$/, arr);
	printf "ssh root@fe80::%s%%%s\n", arr[1], iface;
	exitcode=0;
}

/^..:..:..:..:..:..$/ {
	match($0, /(..):(..):(..):(..):(..):(..)/, arr);
	printf "ssh root@fe80::%x:%x:%x:%x%%%s\n",
		or(lshift(xor("0x" arr[1], 2), 8), "0x" arr[2]),
		or(lshift("0x" arr[3], 8), "0xff"),
		or("0xfe00", "0x" arr[4]),
		or(lshift("0x" arr[5],8),"0x" arr[6]),
		iface;
	exitcode=0;
}

END { exit exitcode; }
'

if [ $? -ne 0 ]
then	echo "Usage : $0 (<ip4pub>|<ip6pub>|<mac>)"
fi