Reverse Lookup in Germany
Created by: thorsten.gehrig,Last modification on Sun 27 of Nov, 2005 [08:03 UTC] by deti
Sysopsis:
This is an agi-script that does a reverse lookup of german telephone numbers.For example:
- you receive a call from 0049-69-123456.
- The script looks the number up from the german telephone book and gives you the name in the variable ${LONGNAME} back.
There is also a cache for storing already resolved numbers and a logfile.
Description:
The script returns ${LONGNAME} - it's also easily possible to get the address information (if provided by the public phonebook).There are two interesting files:
- CACHE="/var/spool/asterisk/invsuche_cache" - Here all numbers and resolved numbers are stored for faster lookup in the future (or manual resolving if number is not in phonebook)
- LOG="/var/log/asterisk/anrufliste_log" - A logfile containing all callers
Example Dialplan
exten => 12345,1,SetLanguage(de)
exten => 12345,2,AGI,reverse.agi| ${CALLERIDNUM}
exten => 12345,3,SetCIDName(${LONGNAME})
exten => 12345,4,SetCIDNum(${CALLERIDNUM})
This is the "reverse.agi"-script - place it in the agi-directory
#!/bin/sh
#
read agi_request
read agi_language
read agi_channel
read agi_type
read agi_uniqueid
read agi_callerid
read agi_dnid
read agi_rdnis
read agi_context
read agi_extension
read agi_priority
read agi_enhanced
read agi_accountcode
read emptyline
#pfad zum cachefile
CACHE="/var/spool/asterisk/invsuche_cache"
#pfad um das tempfile anzulegen
TMPFILE="/tmp/tmpsuche"
LOG="/var/log/asterisk/anrufliste_log"
if [ "$1" == " " ]; then
NAME="anonymer Anrufer"
DETAILS="Keine details"
else
NUMMER=`echo $1 | sed -e "s/\ //g" -e "s/+49/0/"`
#echo "Suche nach $NUMMER im cache"
NAME=`awk -F '\t' '{ if ($1 == "'$NUMMER'") print $2 }' $CACHE`
DETAILS=`awk -F '\t' '{ if ($1 == "'$NUMMER'") print $3 }' $CACHE`
#echo "Name: $NAME"
#echo "Details: $DETAILS"
if [ "$NAME" == "" ]; then
# reverse Lookup via www.dasoertliche.de"
lynx "http://www.dasoertliche.de/DB4Web/es/oetb2suche/home.htm?kw_invers=$NUMMER&main=Antwort&s=2" \
-dump -nolist -connect_timeout=3> $TMPFILE
NAME=`grep printselected.gif -A 2 $TMPFILE | awk '{ if (FNR == 2) print $0 }' | sed -e "s/\ \+//" -e "s/\ \+/\ /g" -e "s/\[_\]//g"`
DETAILS=`grep printselected.gif -A 2 $TMPFILE | awk '{ if (FNR == 3) print $0 }' | sed -e "s/\ \+//" -e "s/\ \+/\ /g" -e "s/\[_\]//g"`
if [ "$NAME" == "" ]; then
if grep "Kein Teilnehmer gefunden" $TMPFILE > /dev/null; then
NAME="Telefonnummer $NUMMER"
DETAILS="Kein Eintrag $2"
fi;
fi;
if [ "$NAME" == "" ]; then
NAME="Telefonnummer $NUMMER"
DETAILS="Fehler $2"
else
echo -e "$NUMMER\t$NAME\t$DETAILS" >> $CACHE
fi;
fi
fi
###
### Here you can add "additional alert code"
###
echo -e "`date +%e.%m\ %H:%M ` $NAME " >>$LOG
echo 'SET VARIABLE LONGNAME '"\"$NAME\"" >/dev/stdout
read in
exit 0
Return codes
Always returns 0.Sample "additional alert code"
Here are some samples what you can also do with this Script:- Sample 1: Show Caller Information on VDR (Video Disc Recorder)
echo -e -n "mesg TEL:$NAME \nquit\n" | telnet vdr.gehrig.lan 2001
echo -e -n "mesg $DETAILS \nquit\n" | telnet vdr.gehrig.lan 2001
- Sample 2: Show Caller Information on dBox2 (running on Linux)
wget "http://172.17.1.150/control/message?popup=Anruf%20von:%20 $NAME%0A$DETAILS"
- Sample 3: Show Caller Information on Windows-Hosts
echo Anruf von $NAME $DETAILS | smbclient -M hostname
Questions
If you have any Questions about this script you can write Mail to mailto:thorsten@gehrig.deSee also
- Asterisk cmd SetCallerID: Set both caller ID name and number
- Asterisk cmd SetCIDNum: Set caller ID number
- Asterisk cmd SetCIDName: Set caller ID name
- The Caller ID FAQ
Go back to Asterisks documentation of application commands

Comments
333Rewritten to hungarian lookup