blob: 06356abc6532c69a0eaf0ba62a2f5c580fd17d7f (
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
|
#!/bin/sh
if [ "$(id -u)" -ne 0 ]
then
exec sudo -- "$0" "$@"
fi
scan_network()
{
ip -oneline addr |
sed -ne 's/.*inet \([^ ]*\) .*/\1/p' |
while read line
do
case "$line" in
127.*) continue ;;
esac
arp-scan "$line" 2>/dev/null
done | while read ip junk
do
case "$ip" in
*.*.*.*) echo $ip ;;
*) continue ;;
esac
done
}
ips=$(scan_network)
mkdir -p /root/.ssh
touch /root/.ssh/authorized_keys
ssh-keyscan - $ips | while read ip key
do
line=$(printf '%s host key @ %s\n' "$key" "$ip")
grep -Fx "$line" /root/.ssh/authorized_keys ||
echo "$line" >> /root/.ssh/authorized_keys
done
|