-
Notifications
You must be signed in to change notification settings - Fork 0
/
s
41 lines (33 loc) · 747 Bytes
/
s
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
38
39
40
41
#!/bin/bash
# Use the correct SSH-User to connect to a system
# based on availbility of Port 80/tcp
user=$USER
arg=$1
if [ "$arg" == "" ]
then
read -e -p "Host to connect to: " host
else
host=${arg##*@}
shift
fi
newhost=$(nc -w2 $host 80 2>/dev/null)
if [ -n "$newhost" ]
then
host=$newhost
fi
if [ "${arg##*@}" != "${arg%%@*}" ]
then
user=${arg%%@*}
else
internal=$(nc -w2 $newhost 80 2>/dev/null)
if [ -z "$internal" ]
then
user="root"
fi
fi
echo >&2
echo -e "\033[1;32mConnecting to \033[1;31m$host\033[1;32m as user \033[1;31m$user\033[m" >&2
echo >&2
echo -en "\033]0;$host\007" >&2
/usr/bin/ssh -o PasswordAuthentication=no -o PreferredAuthentications=publickey -l $user $host $@
echo -en "\033]0;None\007" >&2