PHP code example of edulazaro / laradomains

1. Go to this page and download the library: Download edulazaro/laradomains library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

edulazaro / laradomains example snippets


use EduLazaro\Laradomains\Domain;

$domain = Domain::parse('https://News.BBC.co.uk:8080/path?x=1');

$domain->ascii;          // "news.bbc.co.uk"
$domain->suffix();       // "co.uk"
$domain->registrable();  // "bbc.co.uk"
$domain->subdomain();    // "news"
$domain->tld();          // "uk"

$idn = Domain::parse('ñandú.es');
$idn->ascii;             // "xn--and-6ma2c.es" (what DNS and registries use)
$idn->unicode;           // "ñandú.es" (what a person reads)

Domain::tryParse('127.0.0.1');   // null: IP addresses are not domains

$site = Domain::parse('edulazaro.github.io');

$site->registrable();               // "github.io" (what the registry knows)
$site->registrable(private: true);  // "edulazaro.github.io" (the site the platform gave out)

Domain::parse('аpple.com')->isLookalike();   // true: the first "а" is Cyrillic
Domain::parse('аррӏе.com')->isLookalike();   // true: all Cyrillic, but every letter has a Latin twin
Domain::parse('ñandú.es')->isLookalike();    // false: accented, but one script
Domain::parse('яндекс.com')->isLookalike();  // false: a real Cyrillic word
Domain::parse('аррӏе.ru')->isLookalike();    // false: Cyrillic is the norm under .ru

Domain::parse('аррӏе.com')->skeleton();                                    // "apple.com"
Domain::parse('www.paypa1.com')->imitates(['paypal.com']);                 // "paypal.com"
Domain::parse('gօօgle.com')->imitates(['google.com']);                     // "google.com" (Armenian օ)
Domain::parse('paypal.com.secure-login.io')->impersonates(['paypal.com']); // "paypal.com"
Domain::parse('paypal-secure.com')->impersonates(['paypal.com']);          // "paypal.com"
Domain::parse('paypalooza.com')->impersonates(['paypal.com']);             // null: a part, not a substring
Domain::parse('www.paypal.com')->impersonates(['paypal.com']);             // null: it is the brand

Domain::parse('paypall.com')->typosquats(['paypal.com']);   // "paypal.com"
Domain::parse('arnazon.com')->typosquats(['amazon.com']);   // "amazon.com"
Domain::parse('paypay.com')->typosquats(['paypal.com']);    // null

use EduLazaro\Laradomains\Typosquat;

$typosquat = Domain::parse('goog1e.com')->typosquat(['google.com']);
$typosquat->brand;   // "google.com"
$typosquat->kind;    // Typosquat::LOOKALIKE (also SWAP, EXTRA, MISSING)

// Only the strong kind:
Domain::parse('apples.com')->typosquats(['apple.com'], kinds: [Typosquat::LOOKALIKE]);   // null

Schedule::command('laradomains:update')->monthly();

use EduLazaro\Laradomains\Facades\Domains;

$registration = Domains::rdap('news.bbc.co.uk');   // asks Nominet about bbc.co.uk

$registration->registeredAt;   // CarbonImmutable
$registration->expiresAt;
$registration->registrar;      // the registrar's name
$registration->registrarIanaId;
$registration->abuseEmail;
$registration->status;         // ["client transfer prohibited", ...]
$registration->nameservers;
$registration->dnssec;
$registration->ageInDays();

$age = Domains::age('example.com');                      // from RDAP
$age = Domains::age('ejemplo.es', certificates: true);   // first certificate in the CT logs when the registry has no date
$age = Domains::age('ejemplo.es', wayback: true);        // first Wayback capture

$age->days();             // 10950
$age->years();            // 30.0
$age->since;              // CarbonImmutable
$age->source;             // "rdap", "certificates" or "wayback"
$age->isNewerThan(30);    // registered in the last month?

use EduLazaro\Laradomains\Age\AgeCheck;

$check = Domains::ageCheck('ejemplo.es', certificates: true);

$check->status;      // "found", "none" or "unknown"
$check->age;         // Age|null
$check->reason;      // why there is no date, null when found
$check->failed;      // sources that did not answer: ["rdap"], ["certificates"]...
$check->found();     // a date
$check->definite();  // a date, or a definite "there is none"
$check->failed();    // a lookup failed and no source found a date

$dns = Domains::dns();

$dns->resolves('example.com');      // true
$dns->addresses('example.com');     // ["93.184.215.14", "2606:2800:..."]
$dns->nameservers('example.com');
$dns->mx('example.com');            // lowest priority first
$dns->acceptsMail('example.com');   // true, false, or null when a lookup failed
$dns->txt('example.com');           // multi-string records joined
$dns->records('example.com', 'CNAME');

use EduLazaro\Laradomains\Screen\Screen;

Domains::screen('example.com');                // CLEAN, MALWARE, ADULT or UNKNOWN
Domains::screen('example.com', adult: false);  // malware and phishing only
Domains::screen('example.com', timeout: 1.5);  // on a request path

$verdict = Domains::verdict('example.com');

$verdict->malware;      // false: checked, not malware
$verdict->adult;        // null: the adult resolver did not answer
$verdict->decision();   // "unknown"
$verdict->complete();   // false
$verdict->blocked();    // null: nothing blocked it, but not everything answered

// config/laradomains.php (the defaults)
'timeouts' => ['rdap' => 10, 'dns' => 3, 'screen' => 2, 'wayback' => 20, 'certificates' => 20],
'retries' => ['rdap' => 0, 'dns' => 1, 'screen' => 0, 'wayback' => 1, 'certificates' => 1],
'retry_delay' => ['dns' => 200, 'wayback' => 5000, 'certificates' => 3000],

$check = Domains::ageCheck($domain, certificates: true, timeout: 1.5, retries: 0);    // at most ~3 s
$mail = Domains::dns()->acceptsMail($domain, timeout: 1, retries: 0);                // at most ~3 s
$verdict = Domains::screen($domain, timeout: 1, retries: 0);                         // at most ~1 s

use Illuminate\Support\Facades\RateLimiter;

Domains::beforeRequest(function (string $service) {
    $limits = ['wayback' => 12, 'rdap' => 120];

    if (! isset($limits[$service])) {
        return;
    }

    while (! RateLimiter::attempt("laradomains:{$service}", $limits[$service], fn () => true, 60)) {
        sleep(1);
    }
});

Http::fake([
    'data.iana.org/*' => Http::response(['services' => [[['com'], ['https://rdap.verisign.com/com/v1/']]]]),
    'rdap.verisign.com/*' => Http::response(['events' => [
        ['eventAction' => 'registration', 'eventDate' => '1995-08-14T04:00:00Z'],
    ]]),
]);
bash
php artisan vendor:publish --tag=laradomains-config