Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Rdap Client Laravel Package

certunlp/rdap-client

Laravel-friendly RDAP client for querying domain, IP, and ASN registration data from RDAP servers. Provides simple APIs to fetch and parse RDAP responses, helping you integrate WHOIS-style lookups into PHP apps with minimal setup.

Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package via Composer:
    composer require certunlp/rdap-client
    
  2. Basic RDAP query (e.g., domain lookup):
    use Certunlp\RdapClient\Client;
    
    $client = new Client();
    $response = $client->domain('example.com');
    
  3. Access parsed data (automatically parsed JSON):
    $domainName = $response->get('domainName');
    $entities = $response->get('entities');
    

First Use Case: Domain Registration Data

$client = new Client();
$response = $client->domain('laravel.com');

if ($response->isSuccess()) {
    $registrar = $response->get('entities.0.roles.0'); // e.g., "registrar"
    $events = $response->get('events'); // Creation/last update timestamps
} else {
    // Handle errors (e.g., rate limits, invalid queries)
    $error = $response->getError();
}

Key Starting Points

  • Client Configuration: Set default RDAP endpoints (e.g., ARIN, RIPE) via constructor or setEndpoint().
  • Response Methods: Use $response->get('path.to.field') or $response->all() for raw data.
  • Laravel Integration: Bind the client to the container in config/app.php for dependency injection.

Implementation Patterns

Workflow: IP Network Lookup

// Configure client with custom timeout
$client = new Client(['timeout' => 5]);
$response = $client->network('8.8.8.8/32');

// Process entities (e.g., abuse contacts)
foreach ($response->get('entities') as $entity) {
    if (in_array('abuse', $entity->roles)) {
        $abuseEmail = $entity->vcard[0]->email;
    }
}

Workflow: ASN Lookup with Error Handling

try {
    $response = $client->asn(15169); // Google's ASN
    $asnData = $response->get('asn');
    $startDate = $response->get('startDate');
} catch (\Certunlp\RdapClient\Exception\RdapException $e) {
    // Log or retry (e.g., for rate limits)
    Log::error("RDAP lookup failed: " . $e->getMessage());
}

Integration Tips

  1. Laravel Service Provider:
    // app/Providers/AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(Client::class, function ($app) {
            return new Client(config('rdap.endpoints'));
        });
    }
    
  2. Caching Responses (e.g., for rate-limited queries):
    $cacheKey = "rdap_domain_{$domain}";
    $response = Cache::remember($cacheKey, now()->addHours(1), function () use ($client, $domain) {
        return $client->domain($domain);
    });
    
  3. Batch Lookups (e.g., for bulk domain validation):
    $domains = ['example.com', 'laravel.com'];
    $results = collect($domains)->map(fn ($domain) => $client->domain($domain));
    

Common Use Cases

  • Abuse Contact Lookup: Query IP networks for entities with abuse role.
  • Domain Expiry Check: Parse events for expirationDate.
  • ASN Ownership: Retrieve asn and entities for autonomous system details.

Gotchas and Tips

Pitfalls

  1. Rate Limiting:
    • RDAP endpoints enforce strict rate limits (e.g., 1 request/second). Use caching or exponential backoff:
      $client->setRetryDelay(2); // Retry after 2 seconds on failure
      
  2. Endpoint Availability:
    • Not all RDAP endpoints support all query types (e.g., some may lack ASN lookup). Validate responses:
      if (!$response->isSuccess()) {
          $client->setEndpoint('https://rdap.arin.net'); // Fallback to ARIN
      }
      
  3. JSON Path Complexity:
    • Nested fields (e.g., entities.0.vcard.0.email) may require careful handling. Use get() with dot notation:
      $email = $response->get('entities.*.vcard.*.email'); // Returns all emails
      

Debugging

  • Enable Verbose Logging:
    $client = new Client(['debug' => true]);
    
  • Inspect Raw Responses:
    $rawResponse = $response->getRawResponse();
    
  • Common Errors:
    • 404 Not Found: Invalid query (e.g., non-existent domain/IP).
    • 429 Too Many Requests: Hit rate limits; implement retries.

Extension Points

  1. Custom Response Parsing: Override the default JSON parser by extending Certunlp\RdapClient\Response:
    class CustomResponse extends \Certunlp\RdapClient\Response {
        public function getRegistrar() {
            return $this->get('entities.*.roles.0') === 'registrar';
        }
    }
    
  2. Add Headers:
    $client->setHeaders(['User-Agent' => 'MyApp/1.0']);
    
  3. Proxy Support:
    $client = new Client(['proxy' => 'http://proxy.example.com:8080']);
    

Configuration Quirks

  • Default Endpoint: Falls back to ARIN (https://rdap.arin.net) if none is set.
  • Timeout: Default is 10 seconds; adjust for slow networks:
    $client = new Client(['timeout' => 30]);
    
  • SSL Verification: Disable only if necessary (e.g., for testing):
    $client = new Client(['verify_ssl' => false]);
    

Pro Tips

  • Laravel Artisan Command:
    // app/Console/Commands/LookupDomain.php
    public function handle() {
        $domain = $this->argument('domain');
        $response = app(Client::class)->domain($domain);
        $this->info($response->get('domainName'));
    }
    
  • Queue RDAP Tasks: Use Laravel queues to avoid blocking requests:
    LookupDomainJob::dispatch('example.com')->onQueue('rdap');
    
  • Monitor Response Times: Log duration for performance tuning:
    $start = microtime(true);
    $response = $client->domain('example.com');
    Log::info("RDAP lookup took " . (microtime(true) - $start) . "s");
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware