Rückwärtssuche bei dasoertliche.de neues Script

ok danke sorry mein fehler ...


noch ne frage woher kommt :

[May 3 15:32:49] ERROR[22797]: utils.c:1164 ast_carefulwrite: write() returned error: Broken pipe

?
 
Noch ne kleine Frage .

Hab mal den Countryprefix auf + gesetzt.
my $countryprefix = "+"; #usually 00 or +

jetzt kommt der Fehler :
Code:
SET VARIABLE SPAMSCORE "5"^+ matches null string many times in regex; marked by <-- HERE in m/^+ <-- HERE / at ./reversecheck.agi line 155.
^+ matches null string many times in regex; marked by <-- HERE in m/^+ <-- HERE 49/ at ./reversecheck.agi line 158.
^+ matches null string many times in regex; marked by <-- HERE in m/^+ <-- HERE 41/ at ./reversecheck.agi line 158.
^+ matches null string many times in regex; marked by <-- HERE in m/^+ <-- HERE 43/ at ./reversecheck.agi line 158.

Muss ich das + irgendwie escapen

Gruß
 
Zuletzt bearbeitet von einem Moderator:
Geht leider nicht , gleicher Fehler
 
Weil die dauernd die html Seite umstellen

Code:
#!/usr/bin/perl
# reverse lookup for de,at,ch numbers so the name will be displayed on phone
# name look can be cached in asterisk db or mysql in order to prevent reverse name lookups (tellows spamscore will be still looked up if not stored in phonebook)
# uk and ireland currently has no free reverse lookup serivces.
# found name is stored in asterisk variable ${CALLERID(name)}
# usage: <script> number 1 (for cached lookups, works only if db exists)
#        <script> number 0 (for non-cached lookups)
#        <script> number (uses default set cache mode)


use warnings;
use strict;
use utf8; #disable if page doesnt use utf8
$|=1; # do not buffer output

use Asterisk::AGI; # needed for caching in AstDB, install as root: cpan install "Asterisk::AGI"
my $AGI = new Asterisk::AGI;
use HTML::TreeBuilder 5 -weak; # parses the html page, debian sid unstable: libhtml-tree-perl
use LWP::UserAgent;
use Encode;
use DBI;

###########################
# user defined variables  #
my $countryprefix = "00"; #usually 00 or +
my $cache = 1; #can be enabled permanently, but also be controlled over 2nd start parameter
my $family = "cidcache"; # AstDB family used for caching name of reverse lookups (will be disabled if mysql is used)
my $mysql = 1; #mysql will be used for caching if opion is enabled (disables astdb)
my $mysql_phonebook = 1; #use mysql phonebook for additional searching of name and address, used fields are name,street,areacode,city
my $mysql_db = "asteriskpb";
my $mysql_table = "phonebook"; # used only for lookups
my $mysql_tablecache = "cdrcache"; # used for lookups and caching/storing
my $mysql_host = "localhost";
my $mysql_user = "asterisk";
my $mysql_pwd = "pw";
#############################

my $ua = LWP::UserAgent->new();
my $tellowsresult = "" ;
my ($reverseresult,$reversestreet,$reverseareacode,$reversecity) = "" ; #data for actual reverse lookup
my ($cachename,$cachestreet,$cacheareacode,$cachecity) = "" ; #data for mysql caching
my ($phonename,$phonecontact,$phonestreet,$phoneareacode,$phonecity) = "" ; #data for mysql phonebook
my $number = $ARGV[0];
my $searchnotfound = "Can not find predefined html tag or number was not found!\n";

if (! $ARGV[0]) {
print "\nMissing argument: number!\n";
exit;
}

if (defined $ARGV[1]) { #use as 2nd parameter if found
    $cache = $ARGV[1];
}

my %countrylist = ('at' => 43, 'ch' => 41, 'de' => 49); #sub reverselookup has to be changed if modified
my $countlist = keys %countrylist; #this is currently only used to display error if country was not defined
my $i = 0;

if ($cache == 1) {

    if ($mysql == 1) { # use MySQL

        my $dbh = DBI->connect("DBI:mysql:database=$mysql_db;host=$mysql_host",$mysql_user,$mysql_pwd,
        { RaiseError => 1}
        );

        # get data from caching table
        my $sth = $dbh->prepare("SELECT name,street,areacode,city from $mysql_tablecache WHERE number = ?");
        $sth->execute($number);
        my $result = $sth->fetchrow_hashref();
        $cachename = $result->{name};
        $cachestreet = $result->{street};
        $cacheareacode = $result->{areacode};
        $cachecity = $result->{city};
        $sth->finish();

        if ($mysql_phonebook == 1) {
            #get data from phonebook
            $sth = $dbh->prepare("SELECT name,contact,street,areacode,city from $mysql_table WHERE number = ?");
            $sth->execute($number);
            $result = $sth->fetchrow_hashref();
            $phonename = $result->{name};
            $phonecontact = $result->{contact};
            $phonestreet = $result->{street};
            $phoneareacode = $result->{areacode};
            $phonecity = $result->{city};
        $sth->finish();
        }

        if (defined $phonename) {

            print "\nNo reverse lookup to be done because name already in phone book\n";
            if (defined $phonecity) {
                print "\nSET VARIABLE CALLERID(name) \"${phonename} ${phonecontact} ${phonecity}\"";
            } else {
                print "\nSET VARIABLE CALLERID(name) \"${phonename} ${phonecontact}\"";
            }

        } elsif (defined $cachename){
            tellows();
            print "\nNo reverse lookup to be done because name already cached";
            if (defined $cachecity) {
                print "\nSET VARIABLE CALLERID(name) \"${cachename} ${cachecity}\"";
            } else {
                print "\nSET VARIABLE CALLERID(name) \"${cachename}\"";
            }

        } else {
            tellows();
            print "\nNumber not found in phone book or cache, do reverse lookup";
            reverselookup();

            if (!defined $reverseresult ) { #if no name found in lookup, put unknown as name - otherwise variable is undefined and entry cannot be stored
            $reverseresult = "unknown";
            }

            #store result in mysql for caching
            if ((defined $reversestreet) || (defined $reverseareacode) || (defined $reversecity)) {
                ## store to mysql with address
                $sth = $dbh->prepare("INSERT INTO $mysql_tablecache (number, name, street, areacode, city) VALUES ('$number', '$reverseresult', '$reversestreet', '$reverseareacode', '$reversecity') ON DUPLICATE KEY UPDATE name=VALUES(name),street=VALUES(street),areacode=VALUES(areacode),city=VALUES(city)");
            } else {
                ## store to mysql w/o address
                $sth = $dbh->prepare("INSERT INTO $mysql_tablecache (number, name) VALUES ('$number', '$reverseresult') ON DUPLICATE KEY UPDATE name=VALUES(name)");
            }
            $sth->execute();
            $sth->finish();

        }

        $dbh->disconnect();

    } else { # use AstDB
        tellows();
        my $astdbget = $AGI->database_get($family,$number);
        if (! $astdbget) {
            print "\nNumber not found in cache, do reverse lookup";
            reverselookup();
            if (defined $reverseresult) {
                my $astdbstore = $AGI->database_put($family,$number,$reverseresult);
            }
        } else {
            print "\nNo reverse lookup to be done because name already cached";
            print "SET VARIABLE CALLERID(name) \"${astdbget}\"";
        }
    }




} else { # no caching
    tellows();

    print "\nDo uncached reverse lookup, use 1 as second argument if you want cached lookups";
    reverselookup();
}


sub reverselookup {

if ( grep {/^$countryprefix/} $number ) { #if call from other country

    while ( (my $key, my $value) = each %countrylist ) { #iterate through hash
        if ( grep {/^$countryprefix$countrylist{$key}/} $number ) { #grep country prefix + country code in beginning of phone number
            print "\nCall from country ",$key;
            if ($key eq "at") {
                telefonabc($number);
            } elsif ($key eq "ch") {
                telsearch($number);
            } elsif ($key eq "de") {
                oert($number);
            }

        } else {
                $i = $i+1;
                if ($i == $countlist) {
                    print "\nCountry not defined";
                }
        }
    }

} else { #if number from same country
    print "\ndo oertliches lookup";
    oert($number);
    if (!defined $reverseresult ) { #do klicktel if oertliches did not find
        print "\noertliches not found, do klicktel lookup";
        klick($number);
    }
}

}

## german numbers (de) ##

sub tellows {
    my $urltellows = "http://www.tellows.de/basic/num/".$number;
    my $responsetellows = $ua->get($urltellows);
    $responsetellows->is_success or die "\nHTTP to Tellows failed\n", $responsetellows->status_line, "\n";
    my $htmltellows = HTML::TreeBuilder->new_from_content( $responsetellows->content );

    if ( defined $htmltellows ) {
        $tellowsresult = $htmltellows->look_down(
        _tag => 'span',
        id => 'score');

        if (defined $tellowsresult ) {

            $tellowsresult = $tellowsresult->as_trimmed_text;
            print "\nSET VARIABLE SPAMSCORE \"${tellowsresult}\"";
        } else {
            print "\ntellows: ${searchnotfound}";
        }
    } else {
        print "\nTreebuilder cannot read page!";
    }
}


sub oert {
    my $urloert = "http://www1.dasoertliche.de/?form_name=search_inv&ph=".$number;
    my $responseoert = $ua->get($urloert);
    $responseoert->is_success or die "\nHTTP to Oertliches failed\n", $responseoert->status_line, "\n";
    my $htmloert = HTML::TreeBuilder->new_from_content( $responseoert->content );

    if ( defined $htmloert ) {
        $reverseresult = $htmloert->look_down(
        _tag => 'a',
        class => 'name ');

        my $reverselocation = $htmloert->look_down(
        _tag => 'address');

        if (defined $reverseresult ) {
            #print "Das Oertliche: [", $reverseresult->as_trimmed_text(extra_chars => '[:space:]'), "]\n";
            $reverseresult = $reverseresult->as_trimmed_text;
            chop($reverseresult);

            if (defined $reverselocation) {
                $reverselocation=$reverselocation->as_trimmed_text;
                ($reversestreet, $reverseareacode, $reversecity) = $reverselocation =~ /(^.+\d+),.(\d+).(\S+)/; #split address into 3 variables
            }

            if ((defined $reversestreet) || (defined $reverseareacode) || (defined $reversecity)) {
                print "\nSET VARIABLE CALLERID(name) \"${reverseresult} ${reversecity}\"";
            } else {
                print "\nSET VARIABLE CALLERID(name) \"${reverseresult}\"";
            }
        } else {
            print "\noert: ${searchnotfound}";
        }
    } else {
        print "\nTreebuilder cannot read page!";
    }
}

sub klick {

    my $urlklick = "http://www.klicktel.de/inverssuche/index/search?_dvform_posted=1&phoneNumber=".$number;
    my $responseklick = $ua->get($urlklick);
    $responseklick->is_success or die "\nHTTP to Klicktel failed\n", $responseklick->status_line, "\n";
    my $htmlklick = HTML::TreeBuilder->new_from_content( encode_utf8 $responseklick->content );

    if (defined $htmlklick ) {
        $reverseresult = $htmlklick->look_down(
        _tag => 'div',
        class => 'results direct');

        my $reverselocation = $htmlklick->look_down(
        class => 'entryData');

        if (defined $reverseresult ) {
            $reverseresult = $reverseresult->as_trimmed_text;
#           my $newreverseresult = $reverseresult =~ /^[1][.]\s(.+\w.+)/;
#           print "$newreverseresult";
#           $reverselocation=$reverselocation->as_trimmed_text;
#           ($reversestreet, $reverseareacode, $reversecity) = $reverselocation =~ /(^.+\d+)\s(\d+).(\S+)/; #split address into 3 variables
            print "\nSET VARIABLE CALLERID(name) \"${reverseresult}\""; #address already included in reverseresult


        } else {
        print "\nklick: ${searchnotfound}\n";
        }
    } else {
    print "\nTreebuilder cannot read page!\n";
    }
}

## austria numbers (at) ##

sub telefonabc {
    my $urltelefonabc = "http://www.telefonabc.at/result.aspx?what=".$number;
    my $responsetelefonabc = $ua->get($urltelefonabc);
    $responsetelefonabc->is_success or die "\nHTTP to telefonabc.at failed\n", $responsetelefonabc->status_line, "\n";
    my $htmltelefonabc = HTML::TreeBuilder->new_from_content ( $responsetelefonabc->content );
    if ( defined $htmltelefonabc ) {
        $reverseresult = $htmltelefonabc->look_down(
        _tag => 'span',
        class => 'given-name');

        if (defined $reverseresult ) {
            $reverseresult = $reverseresult->as_trimmed_text;
            print "\nSET VARIABLE CALLERID(name) \"${reverseresult}\"";
        } else {
            print "\ntelefonabc: ${searchnotfound}";
        }
    } else {
        print "\nTreebuilder cannot read page!";
    }
}

## swiss numbers (ch) ##

sub telsearch {
    my $urltelsearch = "http://tel.search.ch/?was=".$number;
    my $responsetelsearch = $ua->get($urltelsearch);
    $responsetelsearch->is_success or die "\nHTTP to tel.search.ch failed\n", $responsetelsearch->status_line, "\n";
    my $htmltelsearch = HTML::TreeBuilder->new_from_content ( $responsetelsearch->content );
    if ( defined $htmltelsearch ) {
        $reverseresult = $htmltelsearch->look_down(
        _tag => 'a',
        class => 'fn org');

        if (defined $reverseresult ) {
            $reverseresult = $reverseresult->as_trimmed_text;
            print "\nSET VARIABLE CALLERID(name) \"${reverseresult}\"";
        } else {
            print "\ntelsearch: ${searchnotfound}";
        }
    } else {
        print "\nTreebuilder cannot read page!";
    }
}
 
Weil die dauernd die html Seite umstellen
Man sollte mal analysieren wie Auerswald die Abfrage bei dasörtliche macht.
Die haben das letzte mal 09-2013 die Abfrage geändert.
 
Nö, die greifen direckt auf "www.dasoertliche.de" zu. Schaut euch mal die Bilder an.
das1.PNGdas1a.PNGdasu1.PNGdasu2.PNG
Das ist die Konfiguration für die unscharfe Suche.
Die scharfe Suche ist etwas umfangreicher.
Ich nutze immer die unscharfe.

Ich hänge euch auch die speziellen Konfig-Dateien hier an.
Original sind die ohne .zip, aber so könnt ihr sie gleich entpacken und lesen.
 

Anhänge

  • de_0005_a.n2n.zip
    549 Bytes · Aufrufe: 8
  • de_1005_a.n2n.zip
    518 Bytes · Aufrufe: 10
Zuletzt bearbeitet:
Scheint aber länger Bestand zu haben, als eure Abfrage ;)
 
Wurde mal wieder geändert.

im Script die ersten drei Zeilen in der function "oertliches" wie folgt anpassen:

Code:
wget -q --tries=3 --timeout=5 -O $TMPFILE "http://www3.dastelefonbuch.de/?kw=$SNUM&s=a20000&cmd=search&ort_ok=0&sp=3&vert_ok=0&aktion=23"
NAME=`grep 'class="name"' $TMPFILE -m 1 | awk -F '"' '{print $4}'`
DETAILS=`grep -i 'class="addr"' $TMPFILE -m 1 | awk -F '"' '{print $6}'`
 
und wieder geändert.

Code:
wget -q --tries=3 --timeout=5 -O $TMPFILE "http://www.dastelefonbuch.de/Rückwärts-Suche/$SNUM"
NAME=`grep 'class="name"' $TMPFILE -m 1 | awk -F '"' '{print $4}' | recode UTF-8..ISO-8859-15`
DETAILS=`grep -i 'class="addr"' $TMPFILE -m 1 | awk -F '"' '{print $6}' | recode UTF-8..ISO-8859-15`
 

Statistik des Forums

Themen
246,347
Beiträge
2,250,587
Mitglieder
374,001
Neuestes Mitglied
curious2315
Holen Sie sich 3CX - völlig kostenlos!
Verbinden Sie Ihr Team und Ihre Kunden Telefonie Livechat Videokonferenzen

Gehostet oder selbst-verwaltet. Für bis zu 10 Nutzer dauerhaft kostenlos. Keine Kreditkartendetails erforderlich. Ohne Risiko testen.

3CX
Für diese E-Mail-Adresse besteht bereits ein 3CX-Konto. Sie werden zum Kundenportal weitergeleitet, wo Sie sich anmelden oder Ihr Passwort zurücksetzen können, falls Sie dieses vergessen haben.