<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TEAM FORREST Blog &#187; enum</title>
	<atom:link href="http://www.teamforrest.com/blog/tag/enum/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.teamforrest.com/blog</link>
	<description>Kamailio, Asterisk, VoIP, and IT Consulting</description>
	<lastBuildDate>Fri, 11 Mar 2011 04:48:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Use ENUM to Save Real MONey</title>
		<link>http://www.teamforrest.com/blog/177/use-enum-to-save-real-money/</link>
		<comments>http://www.teamforrest.com/blog/177/use-enum-to-save-real-money/#comments</comments>
		<pubDate>Thu, 27 May 2010 19:07:58 +0000</pubDate>
		<dc:creator>Fred Posner</dc:creator>
				<category><![CDATA[VoIP]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[lookup]]></category>

		<guid isPermaLink="false">http://www.teamforrest.com/blog/?p=177</guid>
		<description><![CDATA[Ok — it almost rhymed. ENUM (read the wiki) refers to the mapping of telephone numbers to internet addresses. Think of it almost as reverse DNS for your phone number. Although there are many methods of integrating ENUM into your &#8230; <a href="http://www.teamforrest.com/blog/177/use-enum-to-save-real-money/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ok — it almost rhymed.</p>
<p>ENUM (<a href="http://en.wikipedia.org/wiki/ENUM">read the wiki</a>) refers to the mapping of telephone numbers to internet addresses. Think of it almost as reverse DNS for your phone number. Although there are many methods of integrating ENUM into your system, our current &#8220;favorite&#8221; is <a href="http://enumplus.org/">ENUMPlus.org</a>.</p>
<p>From their website:</p>
<blockquote><p>ENUM sources are very segregated and there was no global repository &#8211; until now. ENUMPlus queries all of the top ENUM lookup sources and returns the most accurate result with minimal overhead; meaning you only need to specify one source. ENUMPlus allows you to offload all of the query processing to our powerful servers so you don&#8217;t have to waste time and precious resources.</p></blockquote>
<p>Integrating ENUMplus into <a href="http://www.teamforrest.com/blog/tag/asterisk/">Asterisk</a> can be very quick and there&#8217;s a few choices/methods of going about it. You can choose to use their php scripts, go <a href="http://enumplus.org/wiki/index.php/AsteriskConfiguration16">direct from the dialplan</a>, or run your own lookup script. Here, we&#8217;ve chosen to write our own lookup script that basically does the following:</p>
<ol>
<li>Checks ENUMplus.org for a result (with a 2 second timeout)</li>
<li>Sets a variable of ENUMRESULT and returns to dialplan</li>
<li>The dialplan then evaluates that variable, and if a sip value is provided calls the number directly via SIP.</li>
</ol>
<p>Here&#8217;s an example dialplan:</p>
<pre class="brush: plain; title: ; notranslate">exten =&gt; _X.,1,Set(CALLTO=${EXTEN})
exten =&gt; _X.,n,Goto(out,1)
exten =&gt; out,1,AGI(enumcheck.pl,${CALLTO})
exten =&gt; out,n,GotoIf($[&quot;${ENUMRESULT}&quot; = &quot;FAIL&quot;]?pstn)
exten =&gt; out,n,GotoIf($[${ISNULL(${ENUMRESULT})}]?pstn)
exten =&gt; out,n,Dial(${ENUMRESULT},55)
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;CHANUNAVAIL&quot; ]?pstn)
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;CONGESTION&quot; ]?pstn)
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;BUSY&quot; ]?busy)
exten =&gt; out,n,Hangup()
exten =&gt; out,n(pstn),Dial(SIP/${CALLTO}@yourprovider); or DAHDI, etc.
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;CHANUNAVAIL&quot; ]?busy)
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;CONGESTION&quot; ]?busy)
exten =&gt; out,n,GotoIf($[&quot;${DIALSTATUS}&quot; = &quot;BUSY&quot; ]?busy)
exten =&gt; out,n,Hangup()
exten =&gt; out,n(busy),Busy(5)
exten =&gt; out,n,Hangup()</pre>
<p>And here&#8217;s the script:</p>
<pre class="brush: perl; title: ; notranslate">#!/usr/bin/perl -w
use strict;
$|=1;
my ($phone, $url, $apikey, $result, @sip);

while(&lt;STDIN&gt;) {
	chomp;
	last unless length($_);
}

if ($ARGV[0]) {
	$phone = &amp;URLEncode($ARGV[0]);
} else {
	&amp;setvar(&quot;ENUMRESULT&quot;, &quot;FAIL&quot;);
	&amp;printverbose(&quot;enumlookup: No CALLTO received.&quot;,2);
	exit(0);
}

#Get via WEB
$apikey = &quot;REPLACE WITH YOUR KEY&quot;;
$url = &quot;http://enumplus.org/api&quot;;

$result = qx(curl -m 2 -s -d 'key=$apikey' $url/$phone);

if ($result) {
	if ($result =~ /SIP/i) {
		@sip = split(/\|/, $result);
		&amp;setvar(&quot;ENUMRESULT&quot;, $sip[0]);
		&amp;printverbose(&quot;enumlookup: $sip[0]&quot;,2);
	} else {
		&amp;setvar(&quot;ENUMRESULT&quot;, &quot;FAIL&quot;);
		&amp;printverbose(&quot;enumlookup: No sip address found.&quot;,2);
	}
} else {
	&amp;setvar(&quot;ENUMRESULT&quot;, &quot;FAIL&quot;);
	&amp;printverbose(&quot;enumlookup: Timeout or error&quot;,2);
}

sub URLEncode {
   my $theURL = $_[0];
   $theURL =~ s/([\W])/&quot;%&quot; . uc(sprintf(&quot;%2.2x&quot;,ord($1)))/eg;
   return $theURL;
}

sub setvar {
	my ($var, $val) = @_;
	print STDOUT &quot;SET VARIABLE $var \&quot;$val\&quot; \n&quot;;
	while(&lt;STDIN&gt;) {
		m/200 result=1/ &amp;&amp; last;
	}
	return;
}

sub printverbose {
	my ($var, $val) = @_;
	print STDOUT &quot;VERBOSE \&quot;$var\&quot; $val\n&quot;;
	while(&lt;STDIN&gt;) {
		m/200 result=1/ &amp;&amp; last;
	}
	return;
}</pre>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.teamforrest.com/blog/177/use-enum-to-save-real-money/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

