ZIP Lookup
Posted by Othello
Sunday, December 18, 2005
Description: Looks up the given ZIP code and returns the City, State.
alias zip {
if ($len($1) != 5) || ($1 !isnum) {
echo -a Invalid ZIP.
halt
}
else {
ziplookup $1
}
}
alias ziplookup {
set %zipcode $$1
sockopen ziplookup zipinfo.com 80
}
alias htmlfree {
var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
return %x
}
on *:sockopen:ziplookup:{
sockwrite -n $sockname GET /cgi-local/zipsrch.exe?zip= $+ %zipcode HTTP/1.1
sockwrite -n $sockname Host: zipinfo.com $+ $crlf $+ $crlf
}
on *:sockread:ziplookup:{
if ($sockerr) {
echo -a Error
sockclose ziplookup
halt
}
else {
var %zipread
sockread %zipread
}
if (*is not a valid ZIP code* iswm %zipread) || (*The specified CGI application misbehaved* iswm %zipread) {
echo -a Invalid ZIP
sockclose ziplookup
halt
}
if (*<td align=center>*</font></td><td align=center>*</font></td>* iswm %zipread) {
set %zipresult $remove($remove($htmlfree(%zipread),MailingNameStateCodeZIPCode),%zipcode)
set %zipstate $right(%zipresult,2)
set %zipcity $left(%zipresult,-2)
echo -a %zipcity $+ , %zipstate
sockclose ziplookup
}
}