Web Hosting Talk







View Full Version : This request is a little wierd


volumeserver
05-06-2003, 11:47 PM
Ok i know this may sound a littl wierd but i need the PHP code so i can connect INTERNIC and grab the expire date of the specified domain

I hope someone can help me out with this

Thanks
Daniel

jb4mt
05-07-2003, 10:10 AM
if your PHP is on a Unix box you could use something like

exec("whois example.com");

then parse the output yourself, that is, if there is no PHP library for this. i know there used to be a Perl library, but now that things have opened up to so many registrars, the formatting of what is returned by 'whois' can be drastically different.

axx2k
05-07-2003, 11:01 AM
First, determine the source of the whois results (a registrar you may have an account with, etc). If you plan on using results on your site, you need a url that will post variables back to your local script. Then you can determine how to extract the expiry date from the details.

UH-Matt
05-07-2003, 11:02 AM
Doing it in bulk will end up getting your IP banned from the whois servers.

UH-Matt
05-07-2003, 11:02 AM
Doing it in bulk will end up getting your IP banned from the whois servers.

Saeven
05-07-2003, 11:19 AM
Not all servers are that strict - some will permit a numerous few thousand queries a day before getting hard on you.

A better way of doing a whois is opening a socket to the whois server on port 43 and sending the SLD followed by a line return once the socket is established. You can thereafter read from the socket till its end and retrieve the whois data and parse it as it comes in.

We've found a slight speed advantage to doing it this way over shelling.

Cheers.
A

axx2k
05-07-2003, 11:38 AM
Originally posted by Saeven
Not all servers are that strict - some will permit a numerous few thousand queries a day before getting hard on you.

A better way of doing a whois is opening a socket to the whois server on port 43 and sending the SLD followed by a line return once the socket is established. You can thereafter read from the socket till its end and retrieve the whois data and parse it as it comes in.

We've found a slight speed advantage to doing it this way over shelling.

Cheers.
A


good to know that.... :)

volumeserver
05-07-2003, 10:24 PM
Ok but what are the variables

like

$expirationdate = "WHOIS VARIABLE";

See what i mean?

i only need a few of thge fields that a whois search would get i need the nameservers the expirationdate and the owners name and thats all

Saeven
05-07-2003, 10:31 PM
each whois server has a different format in which they display the dates and nameservers.

So you have to do two things.

If you search for a name you have to:

1. Make sure the name was found. This entails that you have a pattern matcher that will check for a variable or other that will return whether the search was successful or not. Each success will be individual to each whois server.

2. If the search is successful, grab the whole return and parse for the variables you require. The best thing to do would be to use regexps, but if you know that the NSes are prefixed with NAMESERVER1 and NAMESERVER2 a simple strstr can do the trick to see if it exists and then do an explode, a str_replace anything you want to shave off the no good stuff - same with the other details you want.

volumeserver
05-07-2003, 11:29 PM
Ok what i want it to do is

i want to do a whois query on example.com

and i want it to disply something like this

Domain: example.com
Regisrant name: John Doe
Expiration date: 12-21-2003

Can you give me a sample code to do this?

Lightwave
05-08-2003, 04:47 AM
Ok, so it's close...

<?PHP
# daved@lightwave.net
# based on:
# domainwhois v1.0 - micke andersson, root@g33k.net

if ($domain)
{
if ($domain)
{
// first get the domain server from internic. you can also change the alternative
// whois server to something else that suits you.

$fp = fsockopen( "rs.internic.net", 43, &$errno, &$errstr, 10);
if (!$fp)
{
echo "$errstr ($errno)<br>\n";
}
else
{
fputs($fp, "$domain\r\n");
while(!feof($fp))
{
$buf = fgets($fp,128);
if (ereg( "Expiration Date:", $buf))
{
$expire = str_replace( "Expiration Date: ", "", $buf);
$expire = trim($expire);

}
}
fclose($fp);
}
if ($expire)
{
echo "Domain: $domain\n<br>";
echo "Expiration Date: $expire\n<br>";
}
else {
echo( "<b>$domain does not appear to be registered.</b><BR>");
}
echo ( "</PRE><BR>");
}

}
?>
<FORM ACTION=" <?PHP echo($PHP_SELF); ?>" METHOD="post">
This will find .com, .org, and .net domains<br>
domain: <INPUT TYPE="text" NAME="domain" SIZE="40" MAXLENGTH="100">
<INPUT TYPE=submit VALUE="Get Info!"><INPUT TYPE=reset VALUE="Reset">
</FORM>

volumeserver
05-08-2003, 04:51 AM
Thanks alot

I would have never figured it out

Lightwave
05-08-2003, 05:02 AM
Ok.. well as the subject says.. that code only really outputs 2/3rds of the text you were looking for... specificaly it leaves out the Registrant name... because rs.internic.net doesnt display that.


I COULD write something which queryies rs.internic.net and gets the whois server, then queries the whois server and gets the registrant name, expiration date, and blah blah.. but well...

a) i'm lazy
b) there's still the problem that multiple whois servers respond significantly differently and making it work so it'd display properly for each one isnt currently doable because: see problem a)

volumeserver
05-08-2003, 05:05 AM
LOL ok then

Thanks alot for the help

I needed that for the need CPanle theme i created i thought i was gonn ahave to leave that out of the theme but thanks to you i dont have to

Have a look for your self

http://volumeserver.com/cpthemes

I have to update that sample so check back there every few minutes i will update it right now

Lightwave
05-08-2003, 05:40 AM
Again per the text... it's only going to work for limited TLDs (.com, .net, .org, .edu) any ccTLDs it's not going to work for...

So you might want to write a statement in your cpanel theme so that if the domain in question isnt a .com/.net/.org/.edu to not include that bit. Cuz it'd look funny when it replies "Domain doesn't appear to be registered" when it very well might be.

volumeserver
05-08-2003, 05:44 AM
I already did that

I almost didnt untill i realized internic only does TLD's

Thanks for letting me know though
I would have sucked if i didnt realize it


Thanks for all your help

I left the text below in the theme to give you credit for what you did
"
# daved@lightwave.net
# based on:
# domainwhois v1.0 - micke andersson, root@g33k.net
"

Thanks again

Lightwave
05-08-2003, 05:45 AM
This looks a little prettier... and i removed a useless if ($domain) part...


<?PHP
# daved@lightwave.net
# based on:
# domainwhois v1.0 - micke andersson, root@g33k.net

if ($domain)
{
$fp = fsockopen( "rs.internic.net", 43, &$errno, &$errstr, 10);
if (!$fp)
{
echo "$errstr ($errno)<br>\n";
}
else
{
fputs($fp, "$domain\r\n");
while(!feof($fp))
{
$buf = fgets($fp,128);
if (ereg( "Expiration Date:", $buf))
{
$expire = str_replace( "Expiration Date: ", "", $buf);
$expire = trim($expire);
}
}
fclose($fp);
}
if ($expire)
{
echo "Domain: $domain\n<br>";
echo "Expiration Date: $expire\n<br>";
}
else {
echo( "<b>$domain does not appear to be registered.</b><BR>");
}
echo ( "</PRE><BR>");
}
}
?>
<FORM ACTION=" <?PHP echo($PHP_SELF); ?>" METHOD="post">
This will find .com, .org, and .net domains<br>
domain: <INPUT TYPE="text" NAME="domain" SIZE="40" MAXLENGTH="100">
<INPUT TYPE=submit VALUE="Get Info!"><INPUT TYPE=reset VALUE="Reset">
</FORM>

Lightwave
05-08-2003, 05:46 AM
Can you tell i'm bored :)

volumeserver
05-08-2003, 05:47 AM
Just a little

Lightwave
05-08-2003, 05:59 AM
Then give me something else to do :P

<wonders at what point he looses "Newbie" forum status>