<?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>Fred Posner (.com) &#187; Perl</title>
	<atom:link href="http://www.fredposner.com/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fredposner.com</link>
	<description>The World of FISPosner.</description>
	<lastBuildDate>Fri, 27 Jan 2012 21:26:25 +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>Ann Arbor Blocks My Parking App</title>
		<link>http://www.fredposner.com/miscellaneous/442/ann-arbor-blocks-my-parking-app/</link>
		<comments>http://www.fredposner.com/miscellaneous/442/ann-arbor-blocks-my-parking-app/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 00:09:15 +0000</pubDate>
		<dc:creator>Fred Posner</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Ann Arbor]]></category>
		<category><![CDATA[Fred Posner]]></category>
		<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.fredposner.com/?p=442</guid>
		<description><![CDATA[Ann Arbor DDA, you massively fail. If you were a ship, you&#8217;d be the titanic&#8230; Can you believe in today&#8217;s world that a government agency would conspire and discuss the control of public information? What if that information was a &#8230; <a href="http://www.fredposner.com/miscellaneous/442/ann-arbor-blocks-my-parking-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ann Arbor DDA, you massively fail. If you were a ship, you&#8217;d be the titanic&#8230;</p>
<p>Can you believe in today&#8217;s world that a government agency would conspire and discuss the control of public information? What if that information was a top secret as&#8230; parking space availability?</p>
<p>I&#8217;ve posted an article on <a href="http://www.voiptechchat.com/voip/255/a2dda-blocks-asterisk-parking-data" onclick="pageTracker._trackPageview('/outgoing/www.voiptechchat.com/voip/255/a2dda-blocks-asterisk-parking-data?referer=');">VoIP Tech Chat</a> detailing the Ann Arbor DDA doing just that. My response to them is at the end&#8230; Please enjoy.</p>
<p><a href="http://www.voiptechchat.com/voip/255/a2dda-blocks-asterisk-parking-data" onclick="pageTracker._trackPageview('/outgoing/www.voiptechchat.com/voip/255/a2dda-blocks-asterisk-parking-data?referer=');">Read the article on VoIP Tech Chat</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fredposner.com/miscellaneous/442/ann-arbor-blocks-my-parking-app/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fred Posner in the News</title>
		<link>http://www.fredposner.com/miscellaneous/427/fred-posner-in-the-news/</link>
		<comments>http://www.fredposner.com/miscellaneous/427/fred-posner-in-the-news/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 19:02:13 +0000</pubDate>
		<dc:creator>Fred Posner</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Ann Arbor]]></category>
		<category><![CDATA[Fred Posner]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[VoIP]]></category>

		<guid isPermaLink="false">http://www.fredposner.com/?p=427</guid>
		<description><![CDATA[Some of the local papers / sites picked up the Parking Space story&#8230; check it out: Ann Arbor Chronicle HD Teeter Talk Ann Arbor News Arbor Update]]></description>
			<content:encoded><![CDATA[<p>Some of the local papers / sites picked up the Parking Space story&#8230; check it out:</p>
<ul>
<li><a href="http://annarborchronicle.com/2009/01/15/telephony-on-a-teeter-totter/" onclick="pageTracker._trackPageview('/outgoing/annarborchronicle.com/2009/01/15/telephony-on-a-teeter-totter/?referer=');">Ann Arbor Chronicle</a></li>
<li><a href="http://homelessdave.com/tt20090113fredposner.htm" onclick="pageTracker._trackPageview('/outgoing/homelessdave.com/tt20090113fredposner.htm?referer=');">HD Teeter Talk</a></li>
<li><a href="http://www.mlive.com/news/ann-arbor/index.ssf/2009/01/use_your_cell_phone_parking_gee.html" onclick="pageTracker._trackPageview('/outgoing/www.mlive.com/news/ann-arbor/index.ssf/2009/01/use_your_cell_phone_parking_gee.html?referer=');">Ann Arbor News</a></li>
<li><a href="http://arborupdate.com/article/1762/a2-parking-geeks" onclick="pageTracker._trackPageview('/outgoing/arborupdate.com/article/1762/a2-parking-geeks?referer=');">Arbor Update</a></li>
</ul>
<p> <img src='http://www.fredposner.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fredposner.com/miscellaneous/427/fred-posner-in-the-news/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geeky Item of the Day &#8211; Free CNAM</title>
		<link>http://www.fredposner.com/voip/413/geeky-item-of-the-day-free-cnam/</link>
		<comments>http://www.fredposner.com/voip/413/geeky-item-of-the-day-free-cnam/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:57:57 +0000</pubDate>
		<dc:creator>Fred Posner</dc:creator>
				<category><![CDATA[VoIP]]></category>
		<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Tech]]></category>

		<guid isPermaLink="false">http://www.fredposner.com/?p=413</guid>
		<description><![CDATA[Ok, if you use Asterisk (or a Do It Yourself type VoIP service), you sometimes do not receive the CNAM (think Caller ID with Name data) from your carrier. Well, since geeks like information and anything &#8220;free,&#8221; there&#8217;s a simple &#8230; <a href="http://www.fredposner.com/voip/413/geeky-item-of-the-day-free-cnam/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ok, if you use Asterisk (or a Do It Yourself type VoIP service), you sometimes do not receive the CNAM (think Caller ID with Name data) from your carrier. Well, since geeks like information and anything &#8220;free,&#8221; there&#8217;s a simple way to use the internet to do a reverse number lookup query. So, if you&#8217;re a technical type, keep reading&#8230; otherwise, non-geek posts will return very soon.</p>
<p><span id="more-413"></span>So, using a simple Perl script, you can check many resources and attempt to get the calling party&#8217;s name. There are tons of caller id lookup scripts out there, but most require the Asterisk Perl AGI module, a localized NPA/NXX database, or a local database query.</p>
<p>Since I don&#8217;t like installing the module, don&#8217;t want to install a local lookup table, and don&#8217;t wish to cache CID names in a database, I&#8217;ve modified publicly available scripts as follows (<a href="http://www.teamforrest.com/voip/89/using-agi-to-get-caller-id-name-cnam/" onclick="pageTracker._trackPageview('/outgoing/www.teamforrest.com/voip/89/using-agi-to-get-caller-id-name-cnam/?referer=');">also, check up the write up on Team Forrest, with a little more detail</a>):</p>
<p class="alert">Update: AnyWho changed their url and format, the new code is live on <a href="http://www.teamforrest.com/voip/89/using-agi-to-get-caller-id-name-cnam/" onclick="pageTracker._trackPageview('/outgoing/www.teamforrest.com/voip/89/using-agi-to-get-caller-id-name-cnam/?referer=');">Team Forrest</a> but the old code is still below.</p>
<pre>#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
$|=1;
sub trim($);

my %AGI; my $tests = 0; my $fail = 0; my $pass = 0; my $result = ""; my $cidnum = ""; my $cidname = "";
my $npa = ""; my $nxx = ""; my $station = ""; my $name = "";

$cidnum = $ARGV[0];

while(&lt;STDIN&gt;) {
	chomp;
	last unless length($_);
	if (/^agi_(\w+)\:\s+(.*)$/) {
		$AGI{$1} = $2;
	}
}

my $AnyWho = '1' ;
my $Google = '1' ;
my $www411 = '1' ;

if(substr($cidnum,0,1) eq '1'){
$cidnum=substr($cidnum,1);
}

if(substr($cidnum,0,2) eq '+1'){
$cidnum=substr($cidnum,2);
}

if ($cidnum =~ /^(\d{3})(\d{3})(\d{4})$/) {
	$npa = $1;
	$nxx = $2;
	$station = $3;
	}
elsif($cidnum =~/\&lt;(\d{3})(\d{3})(\d{4})\&gt;/){
	$npa = $1;
	$nxx = $2;
	$station = $3;
	}
else {
	print qq(VERBOSE "ERROR: unable to parse caller id" 2\n);
	exit(0);
} 

if ($AnyWho &gt; '0') {
	print qq(VERBOSE "STATUS: checking AnyWho for name lookup" 2\n);
	if ($name = &amp;anywho_lookup ($npa, $nxx, $station)) {
		$cidname = $name;
		print qq(SET VARIABLE CALLERID\(name\) "$cidname"\n);
		print qq(VERBOSE "STATUS: AnyWho said name was $cidname " 2\n);
		exit(0);
		}
	else {
		print qq(VERBOSE "STATUS: unable to find name with AnyWho" 2\n);
		}
	}
else {
	print qq(VERBOSE "STATUS: AnyWho lookup disabled" 2\n);
}

if ($Google &gt; '0') {
	print qq(VERBOSE "STATUS: checking Google for name lookup" 2\n);
	if ($name = &amp;google_lookup ($npa, $nxx, $station)) {
		$cidname = $name;
		print qq(SET VARIABLE CALLERID\(name\) "$cidname"\n);
		print qq(VERBOSE "STATUS: Google said name was $cidname " 2\n);
		exit(0);
		}
	else {
		print qq(VERBOSE "STATUS: unable to find name with Google" 2\n);
		}
	}
else {
	print qq(VERBOSE "STATUS: Google lookup disabled" 2\n);
}

if ($www411 &gt; '0') {
	print qq(VERBOSE "STATUS: checking www411 for name lookup" 2\n);
	if ($name = &amp;www411_lookup ($npa, $nxx, $station)) {
		$cidname = $name;
		print qq(SET VARIABLE CALLERID\(name\) "$cidname"\n);
		print qq(VERBOSE "STATUS: www411 said name was $cidname " 2\n);
		exit(0);
		}
	else {
		print qq(VERBOSE "STATUS: unable to find name with www411" 2\n);
		}
	}
else {
	print qq(VERBOSE "STATUS: www411 lookup disabled" 2\n);
}

print qq(SET VARIABLE CALLERID\(name\) "$cidnum"\n);
print qq(VERBOSE "STATUS: Unknown name for $cidnum " 2\n);
exit(0); 

sub anywho_lookup {
	my ($npa, $nxx, $station) = @_;
	my $ua = LWP::UserAgent-&gt;new( timeout =&gt; 45);
	my $URL = 'http://www.anywho.com/qry/wp_rl';
	$URL .= '?npa=' . $npa . '&amp;telephone=' . $nxx . $station;
	$ua-&gt;agent('AsteriskAGIQuery/1');
	my $req = new HTTP::Request GET =&gt; $URL;
	my $res = $ua-&gt;request($req);
	if ($res-&gt;is_success()) {
		if ($res-&gt;content =~ /&lt;!-- listing --&gt;(.*)&lt;!-- \/listing --&gt;/s) {
			my $listing = $1;
			if ($listing =~ /&lt;B&gt;(.*)&lt;\/B&gt;/) {
				my $clidname = $1;
				return $clidname;
			}
		}
	}
	return "";
}

sub google_lookup {
  my ($npa, $nxx, $station) = @_;
  my $ua = LWP::UserAgent-&gt;new( timeout =&gt; 45);
  my $URL = 'http://www.google.com/search?rls=en&amp;q=phonebook:' .  $npa . $nxx . $station . '&amp;ie=UTF-8&amp;oe=UTF-8';
  $ua-&gt;agent('AsteriskAGIQuery/1');
  my $req = new HTTP::Request GET =&gt; $URL;
  my $res = $ua-&gt;request($req);
  if ($res-&gt;is_success()) {
    if ($res-&gt;content =~ /&lt;font size=-2&gt;&lt;br&gt;&lt;\/font&gt;&lt;font size=-1&gt;(.+)&lt;font color=green&gt;/) {
      my $temp = $1;
      my $clidname = "";
      if ( $temp =~ /(.+)&lt;font color=green&gt;/o ) {
        $clidname = substr($1, 0, -3);
      } else {
        $clidname = substr($temp, 0, -3);
      }
      if ($clidname =~ /&lt;a href(.+)\//) {
        $clidname = $1 ;
        if ($clidname =~ /&gt;(.+)&lt;/) {
          $clidname = $1 ;
        }
      }
      return $clidname;
    }
  }
  return "";
} 

sub www411_lookup {
  my ($npa, $nxx, $station) = @_;
  my $ua = LWP::UserAgent-&gt;new( timeout =&gt; 45);
  my $URL = 'http://www.411.com/search/Reverse_Phone?phone=' .  $npa . $nxx . $station;
  $ua-&gt;agent('AsteriskAGIQuery/1');
  my $req = new HTTP::Request GET =&gt; $URL;
  my $res = $ua-&gt;request($req);
  if ($res-&gt;is_success()) {
    if ($res-&gt;content =~ /Location: &lt;strong&gt;(.*)&lt;\/strong&gt;/s) {
      my $temp = $1;
      my $clidname = "";
      $temp =~ s/&amp;amp\;/&amp;/g;
      $temp =~ s/%20/ /g;
						$clidname = $temp;
		    return $clidname;
     }
  }
  return "";
}</pre>
<p>Basically, what the script does is lookup the cidname from the CID number. I pass the script an argument (the caller id number) and it checks AnyWho, Google, and 411.com (in order). I chose 411 last and just use it to replace an NPA/NXX table. Basically, if AnyWho and Google fail, I&#8217;m assuming it&#8217;s a cell phone or unlisted number and will assume 411 will only return a location. If all fails, the script sets the callerid name to be the callerid number.</p>
<p>I&#8217;ve integrated it into asterisk by first creating a lookup context:</p>
<pre>[cidname-lookup]
exten =&gt; s,1,NoOp(looking up callerid name)
exten =&gt; s,n,GotoIf($["foo${CALLERID(NAME)}" = "foo" ]?getname)
exten =&gt; s,n,GotoIf($["${CALLERID(NAME)}" = "${CALLERID(NUM)}" ]?getname)
exten =&gt; s,n,NoOp(caller id name exists as ${CALLERID(NAME)})
exten =&gt; s,n,Return
exten =&gt; s,n(getname),AGI(calleridname.pl,${CALLERID(NUM)})
exten =&gt; s,n,NoOp(Caller ID Name is now ${CALLERID(NAME)})
exten =&gt; s,n,Return</pre>
<p>Basically, if the callerid name is present (and not the phonenumber), run the script. You can then call the script from anywhere in your Asterisk dialplan using a gosub routine. Such as:</p>
<pre>exten =&gt; s,n,Gosub(cidname-lookup,s,1)
exten =&gt; s,n,dial(${FREDPHONE},30,mt)</pre>
<p>Are there other ways to do this? Absolutely. And some even better <img src='http://www.fredposner.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  This way works for me&#8230; until I see a better way of doing it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fredposner.com/voip/413/geeky-item-of-the-day-free-cnam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geeky Item of the Day</title>
		<link>http://www.fredposner.com/yeni/393/geeky-item-of-the-day/</link>
		<comments>http://www.fredposner.com/yeni/393/geeky-item-of-the-day/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 15:31:32 +0000</pubDate>
		<dc:creator>Fred Posner</dc:creator>
				<category><![CDATA[VoIP]]></category>
		<category><![CDATA[Yeni]]></category>
		<category><![CDATA[Ann Arbor]]></category>
		<category><![CDATA[Geeky]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[polycom]]></category>
		<category><![CDATA[telephone]]></category>

		<guid isPermaLink="false">http://www.fredposner.com/?p=393</guid>
		<description><![CDATA[I have a new phone on my desk (or as Yeni calls it, the mesk). Why mesk? Combines messy and desk… but I digress (as usual). As I was saying, I recently purchased a Polycom Soundpoint IP 450 phone. The &#8230; <a href="http://www.fredposner.com/yeni/393/geeky-item-of-the-day/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_396" class="wp-caption alignright" style="width: 310px"><a href="http://www.fredposner.com/wp-content/uploads/2009/01/polycom-weather.jpg"><img class="size-medium wp-image-396" title="polycom-weather" src="http://www.fredposner.com/wp-content/uploads/2009/01/polycom-weather-300x200.jpg" alt="Yeni Weather Script" width="300" height="200" /></a><p class="wp-caption-text">Yeni Weather Script</p></div>
<p>I have a new phone on my desk (or as Yeni calls it, the mesk). Why mesk? Combines messy and desk… but I digress (as usual).</p>
<p>As I was saying, I recently purchased a <a href="http://www.mgraves.org/voip/2008/11/polycoms-new-soundpoint-ip450/" onclick="pageTracker._trackPageview('/outgoing/www.mgraves.org/voip/2008/11/polycoms-new-soundpoint-ip450/?referer=');">Polycom Soundpoint IP 450 phone</a>. The phone is great — small foot print, clean, great speakerphone, and enables HD Voice. HD Voice is going to change the way we think of how phone calls sound. I admit, I was reluctant at first, but then I got to know <a href="http://www.mgraves.org/voip/" onclick="pageTracker._trackPageview('/outgoing/www.mgraves.org/voip/?referer=');">Michael Graves</a>; and after listening to him praise the benefits of HD Voice for many, many months, I decided it was time to embrace the technology.</p>
<p>Let me say this — HD Voice is amazing. I won&#8217;t say too much more, because I&#8217;m planning to write about it big time on <a href="http://www.voiptechchat.com" onclick="pageTracker._trackPageview('/outgoing/www.voiptechchat.com?referer=');">VoIP Tech Chat</a> and <a href="http://www.teamforrest.com" onclick="pageTracker._trackPageview('/outgoing/www.teamforrest.com?referer=');">Team Forrest</a>; but bottom line: HD Voice = amazing.</p>
<p>So the other nice thing about the phone? It has a little micro-mini browser. Which means what you ask? It means that know whenever Yeni asks me the weather… I can answer. A <a href="http://pbx.teamforrest.com/a2weather.html" onclick="pageTracker._trackPageview('/outgoing/pbx.teamforrest.com/a2weather.html?referer=');">nice little Perl script</a> checks the local Ann Arbor weather and gives me the temp (in F and C), current condition, and quick day&#8217;s forecast. The phone reads the website every 5 minutes and constantly displays the results. It&#8217;s nice. <img src='http://www.fredposner.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.fredposner.com/yeni/393/geeky-item-of-the-day/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

