#!/bin/sh

local_ip_or_device=$1
localaddr="--localaddr $local_ip_or_device"

while read host port
do
    if echo $host | grep -qe "^#"
    then
        continue
    fi
    result=`stunclient $localaddr $host $port`
    if echo $result | grep -qe "^Binding test: success"
    then
        extip=`echo $result | sed -e 's/.*[[:space:]]\+Mapped address:[[:space:]]\+\([^:]\+\):[[:digit:]]\+$/\1/'`    
	echo $extip
	break
    fi
done < /etc/stun-servers.list
