117 lines
9.2 KiB
Markdown
117 lines
9.2 KiB
Markdown
<p align="center"><img src="assets/logo.png" alt="MozOut" width="280"></p>
|
|
|
|
# WHOIS em PHP da MozOut
|
|
|
|
<!-- badges:start -->
|
|
[](https://git.mozout.com/mozout-com/php-whois/releases) [](LICENSE)
|
|
<!-- badges:end -->
|
|
|
|
Uma pequena biblioteca PHP para o WHOIS gratuito da API da MozOut. Saiba se um domínio está livre ou registado, quando expira, os nameservers, quanto custa registar e que nomes parecidos estão livres.
|
|
|
|
[English](README.md)
|
|
|
|
## Instalar
|
|
|
|
```bash
|
|
composer require mozout/php-whois
|
|
```
|
|
|
|
PHP 7.4 ou mais recente, com a extensão json. Mais nenhum pacote. Usa o cURL quando existe e os streams do PHP quando não. Sem Composer, faça `require` do `autoload.php` deste pacote.
|
|
|
|
## Começar
|
|
|
|
```php
|
|
use MozOut\Whois\Client;
|
|
|
|
$whois = new Client();
|
|
$result = $whois->lookup('example.com');
|
|
|
|
if ($result->isAvailable()) {
|
|
echo 'Livre por ' . $result->registerPrice() . ' ' . $result->currency() . ' por ano: ' . $result->registerUrl();
|
|
} elseif ($result->isRegistered()) {
|
|
echo 'Registado até ' . $result->expiresAt()->format('d/m/Y');
|
|
}
|
|
```
|
|
|
|
Não precisa de chave: tem 60 consultas por hora, por IP. Com uma chave da API da sua conta, Sandbox ou Produção, tem 1.000 por hora, por conta (revendedores: 10.000). Crie-a no [API Center](https://www.my.mozout.com/api-center.php) do My MozOut e passe-a, ou defina a variável de ambiente `MOZOUT_API_KEY`:
|
|
|
|
```php
|
|
$whois = new Client(['api_key' => getenv('MOZOUT_API_KEY')]); // igual a new Client() quando a variável existe
|
|
```
|
|
|
|
## O que o resultado dá
|
|
|
|
| Método | O que devolve |
|
|
|---|---|
|
|
| `status()` | `available`, `registered`, `unknown` ou `not_allowed` |
|
|
| `isAvailable()`, `isRegistered()` | `true` ou `false` |
|
|
| `expiresAt()`, `createdAt()`, `updatedAt()` | `DateTimeImmutable` ou `null` |
|
|
| `daysUntilExpiry()`, `nameservers()`, `domainStatus()` | dias, lista de nameservers, lista de estados |
|
|
| `registration()`, `contacts()` | todos os dados de registo e os contactos que a entidade de registo publica |
|
|
| `registerPrice($anos)`, `renewPrice($anos)`, `transferPrice()` | o preço, ou `null` |
|
|
| `currency()`, `isPremium()`, `quoteRequired()` | a moeda, nomes curtos premium, nomes que precisam de cotação |
|
|
| `alternatives()` | até 4 nomes livres, cada um com `domain`, `price` e `register_url` |
|
|
| `registerUrl()`, `transferUrl()` | a página para registar um nome livre ou transferir um registado |
|
|
| `toArray()`, `get('campo')` | tudo o que a API enviou |
|
|
|
|
## Mais
|
|
|
|
Vários domínios num só pedido (até 10, cada um conta 1 no limite):
|
|
|
|
```php
|
|
foreach ($whois->lookupMany(['example.com', 'minhaempresa.com']) as $domain => $r) {
|
|
echo $domain . ': ' . ($r->isError() ? $r->error()['message'] : $r->status()) . PHP_EOL;
|
|
}
|
|
```
|
|
|
|
Preços noutra moeda da marca e ligações do site em português:
|
|
|
|
```php
|
|
$whois = new Client(['currency' => 'USD', 'language' => 'pt']); // em todas as consultas
|
|
$whois->lookup('example.com', ['currency' => 'USD']); // ou só nesta
|
|
```
|
|
|
|
Os erros são excepções que pode apanhar:
|
|
|
|
```php
|
|
use MozOut\Whois\Exception\RateLimitException;
|
|
use MozOut\Whois\Exception\ValidationException;
|
|
use MozOut\Whois\Exception\WhoisException;
|
|
|
|
try {
|
|
$r = $whois->lookup('example.invalid');
|
|
} catch (ValidationException $e) {
|
|
echo $e->getReason(); // extension_not_supported: uma extensão que não vendemos
|
|
} catch (RateLimitException $e) {
|
|
echo $e->getRetryAfter(); // segundos de espera
|
|
} catch (WhoisException $e) {
|
|
echo $e->getMessage(); // qualquer outro; o getCorrelationId() ajuda o suporte
|
|
}
|
|
```
|
|
|
|
Opções de `new Client([...])`: `api_key`, `currency`, `language` (`pt` ou `en`), `timeout` (15 segundos), `retries` (1, só em falhas de rede e 5xx) e `user_agent`.
|
|
|
|
## Testes
|
|
|
|
```bash
|
|
php tests/run.php # sem rede
|
|
php tests/live.php example.com # consultas reais, gasta o seu limite por hora
|
|
```
|
|
|
|
Documentação da API de WHOIS: https://docs.mozout.com/whois/
|
|
|
|
<!-- tlds:start -->
|
|
## Extensões de domínio (502)
|
|
|
|
**Mais procuradas:** `.com`, `.net`, `.org`, `.info`, `.biz`, `.co`, `.io`, `.ai`, `.me`, `.tv`, `.app`, `.dev`, `.online`, `.store`, `.site`, `.shop`, `.tech`, `.xyz`, `.cloud`, `.pro`
|
|
|
|
**Todas as outras:** `.abogado`, `.ac`, `.ac.mz`, `.academy`, `.accountant`, `.accountants`, `.actor`, `.ad`, `.adult`, `.adv.mz`, `.africa.com`, `.agency`, `.airforce`, `.ao`, `.apartments`, `.archi`, `.army`, `.art`, `.asia`, `.associates`, `.attorney`, `.auction`, `.audio`, `.auto`, `.autos`, `.baby`, `.band`, `.bar`, `.barcelona`, `.bargains`, `.beauty`, `.beer`, `.berlin`, `.best`, `.bet`, `.bike`, `.bingo`, `.bio`, `.black`, `.blackfriday`, `.blog`, `.blue`, `.boats`, `.bond`, `.boo`, `.boston`, `.bot`, `.boutique`, `.br`, `.broker`, `.build`, `.builders`, `.business`, `.buzz`, `.ca`, `.cab`, `.cafe`, `.cam`, `.camera`, `.camp`, `.capetown`, `.capital`, `.car`, `.cards`, `.care`, `.career`, `.careers`, `.cars`, `.casa`, `.cash`, `.casino`, `.cat`, `.catering`, `.cc`, `.center`, `.ceo`, `.cfd`, `.channel`, `.charity`, `.chat`, `.cheap`, `.christmas`, `.church`, `.city`, `.claims`, `.cleaning`, `.click`, `.clinic`, `.clothing`, `.club`, `.co.ao`, `.co.mz`, `.co.uk`, `.co.za`, `.coach`, `.codes`, `.coffee`, `.college`, `.community`, `.company`, `.compare`, `.computer`, `.condos`, `.construction`, `.consulting`, `.contact`, `.contractors`, `.cooking`, `.cool`, `.country`, `.coupons`, `.courses`, `.credit`, `.creditcard`, `.cricket`, `.cruises`, `.cv`, `.cymru`, `.cyou`, `.dad`, `.dance`, `.date`, `.dating`, `.day`, `.de`, `.deal`, `.dealer`, `.deals`, `.degree`, `.delivery`, `.democrat`, `.dental`, `.dentist`, `.design`, `.diamonds`, `.diet`, `.digital`, `.direct`, `.directory`, `.discount`, `.diy`, `.doctor`, `.dog`, `.domains`, `.download`, `.durban`, `.eat`, `.eco`, `.edu.ao`, `.edu.mz`, `.education`, `.email`, `.energy`, `.engineer`, `.engineering`, `.enterprises`, `.equipment`, `.es`, `.esq`, `.estate`, `.eu`, `.events`, `.exchange`, `.expert`, `.exposed`, `.express`, `.fail`, `.faith`, `.family`, `.fan`, `.fans`, `.farm`, `.fashion`, `.fast`, `.feedback`, `.finance`, `.financial`, `.fish`, `.fishing`, `.fit`, `.fitness`, `.flights`, `.florist`, `.flowers`, `.fly`, `.fm`, `.foo`, `.food`, `.football`, `.forex`, `.forsale`, `.forum`, `.foundation`, `.free`, `.fun`, `.fund`, `.furniture`, `.futbol`, `.fyi`, `.gallery`, `.game`, `.games`, `.garden`, `.gay`, `.gg`, `.gifts`, `.gives`, `.giving`, `.glass`, `.global`, `.gmbh`, `.gold`, `.golf`, `.gov.mz`, `.graphics`, `.gratis`, `.green`, `.gripe`, `.group`, `.guide`, `.guitars`, `.guru`, `.hair`, `.haus`, `.health`, `.healthcare`, `.help`, `.here`, `.hiphop`, `.hiv`, `.hockey`, `.holdings`, `.holiday`, `.homes`, `.horse`, `.hospital`, `.host`, `.hosting`, `.hot`, `.house`, `.how`, `.icu`, `.id`, `.im`, `.immo`, `.immobilien`, `.in`, `.inc`, `.industries`, `.ing`, `.ink`, `.institute`, `.insure`, `.international`, `.investments`, `.irish`, `.it.ao`, `.je`, `.jetzt`, `.jewelry`, `.kaufen`, `.kids`, `.kim`, `.kitchen`, `.land`, `.lat`, `.latino`, `.law`, `.lawyer`, `.lease`, `.legal`, `.lgbt`, `.life`, `.lifestyle`, `.lighting`, `.limited`, `.limo`, `.link`, `.live`, `.living`, `.llc`, `.loan`, `.loans`, `.locker`, `.lol`, `.london`, `.lotto`, `.love`, `.ltd`, `.luxe`, `.luxury`, `.maison`, `.makeup`, `.management`, `.market`, `.marketing`, `.markets`, `.mba`, `.media`, `.meme`, `.memorial`, `.men`, `.miami`, `.mil.mz`, `.mobi`, `.mobile`, `.moda`, `.mom`, `.money`, `.monster`, `.mortgage`, `.motorcycles`, `.mov`, `.movie`, `.music`, `.my`, `.navy`, `.net.mz`, `.network`, `.new`, `.news`, `.nexus`, `.ninja`, `.nl`, `.now`, `.nyc`, `.observer`, `.one`, `.ong`, `.org.ao`, `.org.mz`, `.page`, `.partners`, `.parts`, `.party`, `.pet`, `.phd`, `.photo`, `.photography`, `.photos`, `.pics`, `.pictures`, `.pink`, `.pizza`, `.place`, `.plumbing`, `.plus`, `.poker`, `.porn`, `.press`, `.productions`, `.prof`, `.promo`, `.properties`, `.property`, `.protection`, `.pub`, `.pw`, `.quest`, `.racing`, `.realty`, `.recipes`, `.red`, `.rehab`, `.reise`, `.reisen`, `.rent`, `.rentals`, `.repair`, `.report`, `.republican`, `.rest`, `.restaurant`, `.review`, `.reviews`, `.rip`, `.rocks`, `.rodeo`, `.rsvp`, `.run`, `.sale`, `.salon`, `.sarl`, `.sbs`, `.school`, `.schule`, `.science`, `.security`, `.select`, `.services`, `.sex`, `.sexy`, `.sh`, `.shiksha`, `.shoes`, `.shopping`, `.show`, `.si`, `.singles`, `.ski`, `.skin`, `.soccer`, `.social`, `.software`, `.solar`, `.solutions`, `.soy`, `.space`, `.spot`, `.storage`, `.stream`, `.studio`, `.study`, `.style`, `.supplies`, `.supply`, `.support`, `.surf`, `.surgery`, `.systems`, `.talk`, `.tattoo`, `.tax`, `.taxi`, `.team`, `.technology`, `.tel`, `.tennis`, `.theater`, `.theatre`, `.tickets`, `.tienda`, `.tips`, `.tires`, `.to`, `.today`, `.tools`, `.top`, `.tours`, `.town`, `.toys`, `.trade`, `.trading`, `.training`, `.tube`, `.uk`, `.university`, `.uno`, `.us`, `.vacations`, `.vana`, `.ventures`, `.vet`, `.viajes`, `.video`, `.villas`, `.vin`, `.vip`, `.vision`, `.vodka`, `.vote`, `.voto`, `.voyage`, `.wales`, `.watch`, `.webcam`, `.website`, `.wedding`, `.wiki`, `.win`, `.wine`, `.work`, `.works`, `.world`, `.wtf`, `.xxx`, `.yachts`, `.yoga`, `.you`, `.za.com`, `.zip`, `.zone`
|
|
<!-- tlds:end -->
|
|
|
|
## Licença
|
|
|
|
MIT. Veja [LICENSE](LICENSE).
|
|
|
|
---
|
|
|
|
Maintained by RLX Holdings.
|