login | register
Fri 09 of Jan, 2009 [01:28 UTC]

voip-info.org

History

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.de

See also



Go back to Asterisks documentation of application commands

Comments

Comments Filter
222

333Rewritten to hungarian lookup

by wpeople, Saturday 15 of October, 2005 [18:22:57 UTC]
#!/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

  1. pfad zum cachefile
CACHE="/var/spool/asterisk/invsuche_cache"

  1. pfad um das tempfile anzulegen
TMPFILE="/tmp/tmpsuche"
LOG="/var/log/asterisk/anrufliste_log"

if "" == " " ; then
   NAME="anonymer Anrufer"
   DETAILS="Keine details"
else

   NUMMER=`echo $1 | sed -e "s/\ //g" -e "s/+36/06/"`    #echo "Suche nach $NUMMER im cache"
area=`echo $1|cut -b3-3`
  1. echo "first byte:$area"
if "$area" == "1" ; then
NUMBER=`echo $NUMMER|cut -b4-10`
else
area=`echo $1|cut -b3-4`
NUMBER=`echo $1|cut -b5-10`
fi
   NAME=`awk  -F '\t' '{ if ($1 == "'$NUMMER'") print $2 }' $CACHE`
   DETAILS=`awk  -F '\t' '{ if ($1 == "'$NUMMER'") print $3 }' $CACHE`
  1. echo "Name: $NAME"
  2. echo "Nummer: ($area) $NUMMER"
   #echo "Details: $DETAILS"
   if  "$NAME" == "" ; then
   # reverse Lookup via www.dasoertliche.de"
       lynx "http://www.tudakozo.t-com.hu/main?session_name=&session_isFonetic=&session_searchType=2&session_c
ustType=0&session_location=&session_zipcode=&session_street=&session_houseNo=&session_areaCode=$area&session_ph
oneNumber=$NUMBER&session_queryType=2&func0=firstQuery%28session_queryType%2Csession_custType%2Csession_searchT
ype%2Csession_name%2Csession_location%2Csession_street%2Csession_zipcode%2Csession_houseNo%2Csession_isFoneticNaV2Csession_phoneNumber%29&xsl=result&xml=result&func_newsess=&OnError=xml%3Dmain%26xsl%3Dmain
"\ -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"`
       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"`
  1. NAME=`cat $TMPFILE|grep \(|head -1`
       NAME=`cat $TMPFILE|head -14|grep "\t"|grep -v track|grep -v telefonsz|grep -v Ã–sszesen|grep -v Elo\"zo\
"|head -1`

       if  "$NAME" == "   alapján tud keresni, az oldalon látható mezo\"k kitöltésével. Ha" ; then
           if grep "Kein Teilnehmer gefunden" $TMPFILE > /dev/null; then
               NAME="Telefonnummer $NUMMER"
               DETAILS="Kein Eintrag $2"
           fi;
       NAME="NF($NUMMER)"
       fi;
       if  "$NAME" == "" ; then
           NAME="Telefonnummer $NUMMER"
           DETAILS="Fehler $2"
       else
           echo -e "$1\t$NAME\t$DETAILS" >> $CACHE
       fi;
   fi
fi

      1. Here you can add "additional alert code"

echo -e "`date +NaVm\ NaVM ` $NAME " >>$LOG
echo 'SET VARIABLE LONGNAME '"\"$NAME\"" >/dev/stdout
read in

exit 0