 | | Offres d'emplois |  | developpeur web Vous souhaitez intégrer une équipe dynamique et créative ? Nous recherchons développeur(euse) pour créer des sites internet à Lille. Connaissances ... | |
 | | Avez vous lu ? |  | | |
|
 Récupération des infos pour une IP | |  |

<?
// --- Récupération des infos pour une IP
class ip_infos {
// --- variables
var $msg_erreur;
var $erreur = 0;
var $serveur_whois = 'whois.arin.net';
var $serveur_whois2 = '';
var $whois_texte = '';
function ip_infos($ip) {
// --- IP valide ?
$host = gethostbyaddr($ip);
if (!$ip == gethostbyname($host)) {
$this->msg_erreur .= "$ip: adresse IP invalide<br>\n";
$this->erreur = 1;
}
// --- connexion au serveur whois
if (!$this->erreur) {
if (!$sock = fsockopen($this->serveur_whois, 43, $num, $error, 20)) {
unset($sock);
$this->msg_erreur .= "Connexion impossible au serveur "
. $this->serveur_whois." (port 43)";
$this->erreur = 2;
}
}
// --- lecture des infos
if (!$this->erreur) {
$this->whois_texte = '';
fputs($sock, $ip."\n");
while (!feof($sock)) {
$this->whois_texte .= fgets($sock, 10240);
}
fclose($sock);
// --- serveur whois complémentaire ?
if (eregi("RIPE.NET", $this->whois_texte)) {
$this->serveur_whois2 = "whois.ripe.net";
}
elseif (eregi("whois.apnic.net", $this->whois_texte)) {
$this->serveur_whois2 = "whois.apnic.net";
}
elseif (eregi("nic.ad.jp", $this->whois_texte)) {
$this->serveur_whois2 = "whois.nic.ad.jp";
// --- suppression des caractères japonais sur JPNIC
$flag = "/e";
}
elseif (eregi("whois.registro.br", $this->whois_texte)) {
$this->serveur_whois2 = "whois.registro.br";
}
}
// --- interrogation du second serveur whois
if($this->serveur_whois2 && !$this->erreur) {
$this->whois_texte = "";
if(! $sock = fsockopen($this->serveur_whois2, 43, $num, $error, 10)) {
unset($sock);
$this->msg_erreur .= "Connexion impossible au serveur "
. $this->serveur_whois2 ." (port 43)";
}
else {
fputs($sock, $ip.$flag."\n");
while (!feof($sock)) {
$this->whois_texte .= fgets($sock, 10240);
}
fclose($sock);
}
}
if(!$this->erreur) {
$tb_lignes = explode(chr(10), $this->whois_texte);
$this->infos = array();
for ($i=0; $i<count($tb_lignes); $i++) {
$tmptb = explode(":", $tb_lignes[$i]);
if (count($tmptb) > 1 && substr($tmptb[0], 0, 1)!='%') {
$key = trim($tmptb[0]);
$val = trim($tmptb[1]);
if(strlen($this->infos["$key"]) > 0) {
$this->infos["$key"] .= ', ' . $val;
}
elseif ($key) $this->infos["$key"] = $val;
}
}
}
}
}
?>
|
|
|
 |
|