Skip to content

Instantly share code, notes, and snippets.

@dangowrt
Created April 21, 2015 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangowrt/37d956fc2f54fd59e7db to your computer and use it in GitHub Desktop.
Save dangowrt/37d956fc2f54fd59e7db to your computer and use it in GitHub Desktop.
kad164: pseudo-e164 dialplan helper script using kadnode
#!/bin/sh
NUM="$1"
uri=""
num2name() {
l=${#NUM}
i=$l
while [ $i -gt 0 ]; do
n="$( echo "$NUM" | cut -b ${i} )"
echo -n "$n."
i=$(( $i - 1 ))
done
echo "e164.p2p"
}
qs="$( num2name "$1" )"
kadnode-ctl lookup $qs 2>/dev/null | while read res; do
ip="$( echo $res | cut -d':' -f1 )"
port="$( echo $res | cut -d':' -f2 )"
proto=""
case "$port" in
5060)
proto=""
;;
5061)
proto=";proto=tls"
;;
esac
[ "$m" ] && echo -n "&"
echo -n "SIP/${1}@$ip$proto"
m=1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment