Code Monkey home page Code Monkey logo

php-whois's Introduction

PHP WHOIS

PHP WHOIS client implementation. Provides raw-text and parsed answers. Sends WHOIS queries to real service via port 43

Build Status PHP version Packagist

Requirements

  • PHP >= 5.4 (compatible with 7.0 up to nightly)
  • intl

Installation

Via Composer cli command

composer require io-developer/php-whois

Or via composer.json

"require": {
    "io-developer/php-whois": "^2.3.0"
}

Usage

Whois client creation

<?php

require_once '../vendor/autoload.php';

use Iodev\Whois\Whois;

$whois = Whois::create();

Domain availability

<?php

use Iodev\Whois\Whois;

if (Whois::create()->isDomainAvailable("google.com")) {
    echo "Bingo! Domain is available! :)";
}

Domain lookup

<?php

use Iodev\Whois\Whois;

$response = Whois::create()->lookupDomain("google.com");
echo $response->getText();

Parsed domain info

<?php

use Iodev\Whois\Whois;

$info = Whois::create()->loadDomainInfo("google.com");
echo "Domain created: " . date("Y-m-d", $info->getCreationDate());
echo "Domain expires: " . date("Y-m-d", $info->getExpirationDate());
echo "Domain owner: " . $info->getOwner();

Advanced usage

Сommon client powered by memcached

<?php

use Iodev\Whois\Whois;
use Iodev\Whois\Loaders\SocketLoader;
use Iodev\Whois\Loaders\MemcachedLoader;

$m = new Memcached();
$m->addServer('127.0.0.1', 11211);
$loader = new MemcachedLoader(new SocketLoader(), $m);

$whois = Whois::create(null, $loader);

Complete domain info loading

<?php

use Iodev\Whois\Whois;
use Iodev\Whois\Exceptions\ConnectionException;
use Iodev\Whois\Exceptions\ServerMismatchException;

$whois = Whois::create();
try {
    $info = $whois->loadDomainInfo("google.com");
    if (!$info) {
        echo "Null if domain available";
        exit;
    }
    echo $info->getDomainName() . " expires at: " . date("d.m.Y H:i:s", $info->getExpirationDate());
} catch (ConnectionException $e) {
    echo "Disconnect or connection timeout";
} catch (ServerMismatchException $e) {
    echo "Domain zone servers (.com for google.com) not found in current ServerProvider whois hosts";
}

Original WHOIS answer via lookup

<?php

use Iodev\Whois\Whois;

$response = Whois::create()->lookupDomain("google.com");
echo $response->getText();

Original WHOIS answer via domain info

<?php

use Iodev\Whois\Whois;

$info = Whois::create()->loadDomainInfo("google.com");
$resp = $info->getResponse();

echo "WHOIS response for '{$resp->getDomain()}':\n{$resp->getText()}";

Сustom whois hosts

<?php

use Iodev\Whois\Server;
use Iodev\Whois\Whois;
use Iodev\Whois\Parsers\CommonParser;

$whois = Whois::create();

// Define custom whois host
$customServer = new Server(".co", "whois.nic.co", false, new CommonParser());

// Or define the same via assoc way
$customServer = Server::fromData([
    "zone" => ".co",
    "host" => "whois.nic.co",
]);

// Append to existing provider
$whois->getServerProvider()->addOne($customServer);

// Now you can load info
$info = $whois->loadDomainInfo("google.co");

var_dump($info);

php-whois's People

Contributors

io-developer avatar

Watchers

James Cloos avatar Alberto Benavente avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.