Skip to content

Commit

Permalink
Merge pull request #1053 from furushchev/use-hostname-to-search-ip
Browse files Browse the repository at this point in the history
[jsk_tools] use hostname to search ip
  • Loading branch information
garaemon committed Jul 30, 2015
2 parents 1cf8d0a + ee1c10a commit aa5d1a9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions jsk_tools/env-hooks/99.jsk_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,19 @@ rossetip_addr() {
if [ "$(echo $target_host | sed -e 's/[0-9\.]//g')" != "" ]; then
target_hostip=$(timeout 0.001 getent hosts ${target_host} | cut -f 1 -d ' ')
fi
if [ "$target_hostip" = "" ]; then target_hostip=$target_host; fi
local mask_target_ip=$(echo ${target_hostip} | cut -d. -f1-3)
export ROS_IP=$(PATH=$PATH:/sbin LANGUAGE=en LANG=C ifconfig | grep inet\ | sed 's/.*inet addr:\([0-9\.]*\).*/\1/' | tr ' ' '\n' | grep $mask_target_ip | head -1)
export ROS_HOSTNAME=$ROS_IP
for ip in $(hostname -I); do
if echo $ip | egrep "^172.17.42.|^127.0."; then
# skip docker/local host
continue
elif [ "${mask_targetip}" = "" ]; then
export ROS_IP=$ip
elif echo $ip | grep $mask_target_ip; then
export ROS_IP=$ip
break
fi
done
export ROS_HOSTNAME=$ROS_IP
}

rossetip() {
Expand Down

0 comments on commit aa5d1a9

Please sign in to comment.