diff --git a/scripts/mosh.pl b/scripts/mosh.pl index f224ef348..3ee8820dc 100755 --- a/scripts/mosh.pl +++ b/scripts/mosh.pl @@ -335,8 +335,9 @@ sub predict_check { if ( $use_remote_ip eq 'local' ) { # "parse" the host from what the user gave us my ($user, $host) = $userhost =~ /^((?:.*@)?)(.*)$/; + my $sshhost = `ssh -G $userhost | awk '/^hostname /{print \$NF}' | tr -d '[:space:]'`; # get list of addresses - my @res = resolvename( $host, 22, $family ); + my @res = resolvename( ( $host eq $sshhost ) ? $host : $sshhost, 22, $family ); # Use only the first address as the Mosh IP my $hostaddr = $res[0]; if ( !defined $hostaddr ) { @@ -347,7 +348,7 @@ sub predict_check { die( "could not use address for $host" ); } $ip = $addr_string; - $userhost = "$user$ip"; + $userhost = "$user$host"; } my $pid = open(my $pipe, "-|");