Skip to content

Instantly share code, notes, and snippets.

@bitbonsai
Created December 16, 2013 20:36
Show Gist options
  • Save bitbonsai/7993911 to your computer and use it in GitHub Desktop.
Save bitbonsai/7993911 to your computer and use it in GitHub Desktop.
PHP Script with cURL to query the brazilian whois database
<?php
function get_br_whois( $url, $array_fields )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "PHP Whois/Curl script", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => http_build_query($array_fields),
CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
// the return is a webpage... stripping useless data (menu, links) and trim it...
$trim_content = substr($content, strpos($content, '% Copyright'));
return array('header' => $header, 'content' => trim(strip_tags(utf8_encode($trim_content))));
}
// and now let's get it...
print_r(
get_br_whois('https://registro.br/cgi-bin/whois/', array('qr' => 'g1.com.br'))
);
// OUTPUTS:
/*
$ php whois.php
Array
(
[header] => Array
(
[url] => https://registro.br/cgi-bin/whois/
[content_type] => text/html
[http_code] => 200
[header_size] => 172
[request_size] => 198
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.813351
[namelookup_time] => 0.000754
[connect_time] => 0.079845
[pretransfer_time] => 0.810219
[size_upload] => 12
[size_download] => 3408
[speed_download] => 1879
[speed_upload] => 6
[download_content_length] => -1
[upload_content_length] => 12
[starttransfer_time] => 0.891525
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 200.160.2.3
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 10.1.1.101
[local_port] => 61115
[errno] => 0
[errmsg] =>
)
[content] => % Copyright (c) Nic.br
% A utilização dos dados abaixo é permitida somente conforme
% descrito no Termo de Uso (http://registro.br/termo), sendo
% proibida a sua distribuição, comercialização ou reprodução,
% em particular para fins publicitários ou propósitos
% similares.
% 2013-12-16 18:31:35 (BRST -02:00)
domínio: g1.com.br
titular: Globo Comunicação e Participaçoes SA
documento: 027.865.757/0021-48
responsável: Regina Sampaio
país: BR
c-titular: RES59
c-admin: RES59
c-técnico: CTG6
c-cobrança: RES59
servidor DNS: ns01.oghost.com.br
status DNS: 15/12/2013 AA
último AA: 15/12/2013
servidor DNS: ns02.oghost.com.br
status DNS: 15/12/2013 AA
último AA: 15/12/2013
servidor DNS: ns03.oghost.com.br
status DNS: 15/12/2013 AA
último AA: 15/12/2013
servidor DNS: ns04.oghost.com.br
status DNS: 15/12/2013 AA
último AA: 15/12/2013
criado: 20/02/2006 #2632955
expiração: 20/02/2017
alterado: 29/05/2013
status: publicado
Contato (ID): CTG6
nome: Contato Técnico - Globo.com
e-mail: fapesp@corp.globo.com
criado: 19/06/2000
alterado: 19/06/2013
Contato (ID): RES59
nome: Regina Sampaio
e-mail: fapesp@corp.globo.com
criado: 10/11/1999
alterado: 24/09/2013
% Problemas de segurança e spam também devem ser reportados ao
% cert.br, http://cert.br/, respectivamente para cert@cert.br
% e mail-abuse@cert.br
%
% whois.registro.br aceita somente consultas diretas. Tipos
% de consultas são: dominio (.br), titular (entidade),
% ticket, provedor, contato (ID), bloco CIDR, IP e ASN.
)
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment