only display certain fields of a whois result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
volumeserver
Forum Newbie
Posts: 4
Joined: Wed May 07, 2003 10:42 pm

only display certain fields of a whois result

Post by volumeserver »

I am trying to find a code that will only display two fields of a whois query

i want a code that will make the output something similar to the below

Registra: ABC registra
Nameservers: ns1.example.com,ns2.example.com
Expiration date: 12-30-2003

Can anyone help me out?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

what's your current code?
volumeserver
Forum Newbie
Posts: 4
Joined: Wed May 07, 2003 10:42 pm

Post by volumeserver »

I dont have one

Sorry
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

do you want to use a local whois-application?
volumeserver
Forum Newbie
Posts: 4
Joined: Wed May 07, 2003 10:42 pm

Post by volumeserver »

I was hoping to use internic

Im sorry but i am very unfamiliar with the "whois" process
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

internic offers a web-interface to its database. Please note
For Whois information about country-code (two-letter) top-level domains, try Uwhois.com
so cannot get the whois entry for e.g. http://www.heise.de from internic.
To get the whois entry for http://www.php.net you can use the link
http://reports.internic.net/cgi-bin/who ... ype=domain

Code: Select all

<?php
$domain = 'php.net';
$url = 'http://reports.internic.net/cgi-bin/whois?whois_nic='.$domain.'&type=domain';
readfile($url);
?>
but you want the data for processing not only to display it

Code: Select all

<?php

$domain = 'php.net';
$url = 'http://reports.internic.net/cgi-bin/whois?whois_nic='.$domain.'&type=domain';
$result = file_get_contents($url); // php4.3+ function
?>
now you have to separate the useful data. I chose <pre>...>>> to limit the search

Code: Select all

<?php
$posStart = strpos($result, '<pre>');
$posEnd = strpos($result, '>>>', $posStart);
$result = substr($result, $posStart, $posEnd-$posStart);
?>
and then a regular expression to extract the fields

Code: Select all

<?php
$info = preg_match_all("!^\s+([^:]*):\s(.*)\n!mi", $result, $matches);
echo '<pre>';
print_r($matches);
echo '</pre>';
?>
There are probably better ways to perform this and no error checking is included.
Please do not abuse the web-interface by querrying each host that requests a document from your server.
volumeserver
Forum Newbie
Posts: 4
Joined: Wed May 07, 2003 10:42 pm

Post by volumeserver »

Acctually im using it in a CPanel Theme everytime a customer logs in to CPanel there is a section that will display the expiration date of there domain
Post Reply