Visualizzazione dei risultati da 1 a 3 su 3

Discussione: whois

  1. #1

    whois

    salve ragazzi ho preso lo script sul sito del whois sono alle prime armi e sono giorni e notti che cerco di far funzionare questo whois qualcuno saprebbe indirizzarmi come realizzare un form con una casella di testo una casella combinata e un pulsante per fare la ricerca dei domini? Questo è il codice:
    <?php
    /******************
    file esempio2.php
    *******************/

    /*
    Includiamo le classi
    */
    include_once('./whoisClasses.php') ;


    /*
    Definiamo alcuni oggetti WHOISdb precisando per ognuno il server e la stringa che indica la disponibilità del dominio.
    Aggiungi gli altri che ti interessano.
    */
    $itnicObj = new WHOISdb('whois.nic.it', 'no entries found') ;

    $internicObj = new WHOISdb('whois.internic.net', 'no match for') ;

    $orgObj = new WHOISdb('whois.publicinterestregistry.net', 'not found') ;

    $bizObj = new WHOISdb('whois.nic.biz', 'not found') ;


    /*
    Array che associa i TLD al corretto WHOIS database
    */
    $tldList = array(

    'it' => $itnicObj,
    'com' => $internicObj,
    'net' => $internicObj,
    'org' => $orgObj,
    'biz' => $bizObj

    ) ;

    /*
    I dati provenienti da un ipotetico form
    con 2 campi: uno per selezionare il TLD e l'altro per il dominio di secondo livello
    */

    $domain = 'whois.html' ;
    $tld = 'it' ;

    if(!$resultObj = $tldList[ $tld ]->checkDomain($domain, $tld)){

    die('Si sono verificati dei problemi, ci scusiamo per il disservizio') ;
    /*
    debug
    */
    //$tldList[ $tld ]->getErrors() ;
    }

    elseif( $resultObj->isAvailable() ){

    echo(''.$resultObj->getDomain().' è disponibile') ;

    }

    else{

    echo(''.$resultObj->getDomain().' non è disponibile

    ') ;
    echo('Ecco i dettagli

    <pre>'.$resultObj->getInfo().'</pre>') ;
    }

    ?>


    QUESTA E' LA CLASSE:


    <?php
    /**
    * Classe per la gestione degli errori
    */
    class ErrorHandler {
    var $errors ;
    var $TCP_CANNOT_CONNECT ;
    var $TCP_CANNOT_SEND ;
    var $TCP_CANNOT_READ ;
    var $TCP_CANNOT_DISCONNECT ;
    var $DOMAIN_NOT_VALID ;

    function ErrorHandler()
    {
    /**
    * Un messaggio per ogni tipo di errore che intendiamo intercettare
    */
    $this->TCP_CANNOT_CONNECT = 'Impossibile connettersi a ' ;
    $this->TCP_CANNOT_SEND = 'Impossibile inviare la seguente request: ' ;
    $this->TCP_CANNOT_READ = 'Impossibile lettura da ' ;
    $this->TCP_CANNOT_DISCONNECT = 'Impossibile chiudere la connessione a ' ;
    $this->DOMAIN_NOT_VALID = 'Nome dominio non valido: ' ;

    $this->errors = array() ;
    }

    /**
    * Aggiunge l'errore alla lista
    */
    function addError($msg)
    {
    $this->errors[] = $msg ;
    }

    /**
    * Recupera la lista degli errori
    */
    function getErrors()
    {
    $errorList = '' ;

    foreach($this->errors as $v) {
    $errorList .= $v . "\n" ;
    }

    return($errorList) ;
    }
    } //END class ErrorHandler
    /**
    * La classe principale:
    *connesssione, query e lettura dei risultati da un WHOIS
    */
    class WHOISdb extends ErrorHandler {
    var $target ;
    var $port ;
    var $link ;
    var $timeout ;
    var $crlf ;
    var $notFound ;
    var $info ;

    /**
    * Costruttore
    */
    function WHOISdb($target, $notFoundMsg, $port = 43, $timeout = 30, $br = "\r\n")
    {
    $this->ErrorHandler() ;
    $this->target = $target ;
    $this->port = $port ;
    $this->timeout = $timeout ;
    $this->crlf = $br ;

    $this->notFound = $notFoundMsg ;
    $this->info = '' ;
    } //END contructor
    /**
    * Metodo privato per la connessione
    */
    function _connect()
    {
    if (!$this->link = fsockopen($this->target, $this->port, $errno, $errstr, $this->timeout)) {
    $this->addError($this->TCP_CANNOT_CONNECT . $this->target . ':' . $this->port) ;
    return(false) ;
    }

    return(true) ;
    } //END _connect
    /**
    * Metodo privato per invio di una request
    */
    function _send($domainStr)
    {
    if (!fputs($this->link, $domainStr . $this->crlf)) {
    $this->addError($this->TCP_CANNOT_SEND . $domain . '.' . $tld) ;
    return(false) ;
    }

    return(true) ;
    } //END _send
    /**
    * Metodo privato per la cattura del response
    */
    function _get()
    {
    $dati = '' ;

    /**
    * Stabilisce il tempo di attesa max prima
    * dell'inizio della lettura dei dati
    */
    if (function_exists('stream_set_timeout')) {
    stream_set_timeout($this->link, $this->timeout, 0);
    } while (!feof($this->link) && $line = fgets ($this->link, 4096)) {
    if ($line === false || $line === 0) {
    $this->addError($this->TCP_CANNOT_READ . $this->target) ;

    return(false) ;
    }

    $dati .= $line ;
    }

    return($dati) ;
    } //END _get
    /**
    * Metodo principale (pubblico), è il metodo che
    * controlla la disponibilità del dominio,
    * verificando la presenza della stringa $this->notFound.
    * Crea l'oggetto WHOISresult
    */
    function checkDomain($domain, $tld)
    {
    $pattern = '<^[0-9A-Za-z]([0-9A-Za-z]|-)+[0-9A-Za-z]\.[A-Za-z]{2,4}(\.[A-Za-z]{2,4})?$>' ;

    $domainStr = $domain . '.' . $tld ;

    /**
    * Verifica la validità dei caratteri del dominio
    */
    if (!preg_match($pattern, $domainStr)) {
    $this->addError($this->DOMAIN_NOT_VALID . $domainStr) ;
    return(false) ;
    } elseif (!$this->_connect()) {
    return(false) ;
    } elseif (!$this->_send($domainStr)) {
    return(false) ;
    } elseif (!$this->info = $this->_get()) {
    return(false) ;
    }

    $disponibile = (bool)stristr($this->info, $this->notFound) ;

    return(new WHOISresult($domainStr, $disponibile, $this->info)) ;
    }
    } //END class WHOISdb
    /**
    * Classe da cui si istanziano gli oggetti
    * risultato delle query
    */
    class WHOISresult {
    /**
    * Costruttore
    */
    function WHOISresult($domain, $disponibile, &$info)
    {
    $this->domain = $domain ;
    $this->disponibile = $disponibile ;
    $this->info = &$info ;
    }

    /**
    * Dice se il domain è disponibile oppure no
    */
    function isAvailable()
    {
    return($this->disponibile) ;
    }

    /**
    * Restituisce il nome del dominio richiesto
    */
    function getDomain()
    {
    return($this->domain) ;
    }

    /**
    * Restituisce la risposta completa del servizio WHOIS
    */
    function getInfo()
    {
    return($this->info) ;
    }
    } //END class WHOISresult

    ?>
    GRAZIE ANTICIPATAMENTE

  2. #2
    perchè non metti il codice tra i tags: /[php/] /[//php/] ??
    Alla batteria dai retta,balla!

  3. #3

    whois

    che intendi tra i tag? come gia detto sono neofita, questo codice l'ho preso nel sito e vorrei delucidazioni su come farlo funzionare...Potete aiutarmi?
    grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.