|
|
|
| Title : |
DNS and Whois Lookup - allows you to quickly find information about a url or ip address |
| Categories : |
PHP |
 Sarah King |
| Date : |
Sep 22nd 2004 |
| Grade : |
2 of 5 (graded 9 times) |
| Viewed : |
7804 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Sarah King |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
Name: DNS and Whois Lookup
allows you to quickly find information about a url or ip address
The array $masters will need to be maintained
as this information changes over time.
The script uses standard PHP calls and has been tested using PHPv4.3.8
Author: Sarah King
Demo: http://sarahk.pcpropertymanager.com/muck/dns/index.php
Date: 22/09/2004
Limitations: Will not work on a Windows Server
Support: Post any questions at http://www.weberforums.com/forum3.html
Credits:
http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1476&lngWId=8
http://www.canufly.net/~georgegg/
| <?php
function getPostVar($name, $default='')
{
global $_POST;
if (isset($_POST[$name]))
{
if (is_array($_POST[$name]))
{
$output = array();
foreach($_POST[$name] as $val) $output[] = $val;
}
else $output = $_POST[$name];
}
else $output = $default;
return trim($output);
}//getPostVar
function requestWhois($whois, $hostname)
{
$fp = fsockopen($whois, 43, $errno, $errstr, 30);
if (!$fp)
{
$output = "$errstr ($errno)";
}
else
{
fputs($fp, "$hostname\r\n");
$output = "<pre>\r\n";
while (!feof($fp)) $output .= fread($fp,128);
$output .= "</pre>";
fclose ($fp);
}
return $output;
}//requestWhois($whois, $hostname)
$masters = array(
'tv' => 'cwhois1.completewhois.com',
'ro' => 'cwhois1.completewhois.com',
'jp' => 'cwhois1.completewhois.com',
'ws' => 'cwhois1.completewhois.com',
'ph' => 'cwhois1.completewhois.com',
'com' => 'cwhois1.completewhois.com',
'fm' => 'cwhois1.completewhois.com',
'vu' => 'cwhois1.completewhois.com',
'be' => 'whois.ripe.net',
'de' => 'whois.ripe.net',
'dk' => 'whois.ripe.net',
'com.ro' => 'whois.ripe.net',
'lt' => 'whois.ripe.net',
'co.il' => 'whois.ripe.net',
'org.il' => 'whois.ripe.net',
'ms' => 'whois.adamsnames.tc',
'gs' => 'whois.adamsnames.tc',
'vg' => 'whois.adamsnames.tc',
'tc' => 'whois.adamsnames.tc',
// 'com' => 'whois.networksolutions.com',
'net' => 'whois.networksolutions.com',
'net.nz' => 'whois.patho.gen.nz',
'org.nz' => 'whois.patho.gen.nz',
'co.nz' => 'whois.domainz.net.nz',
'org' => 'whois.publicinterestregistry.net',
'nl' => 'whois.domain-registry.nl',
'ac' => 'whois.nic.ac',
'as' => 'whois.nic.as',
'cc' => 'whois.nic.cc',
'sh' => 'whois.nic.sh',
'st' => 'whois.nic.st',
'co.uk' => 'whois.nic.uk',
'org.uk' => 'whois.nic.uk',
'co.za' => 'whois.frd.ac.za',
'ca' => 'whois.cdnnet.ca',
'info' => 'whois.afilias.net',
'biz' => 'whois.pacificroot.com',
'to' => 'whois.tonic.to',
'kz' => 'whois.domain.kz',
);
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Whois a domain</title>
<style>
body{
font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size : 12px;
}
h1{
font-size : 16px;
}
h2{
font-size : 14px;
}
pre{
font-family : "Courier New", Courier, monospace;
font-size : 12px;
border : 1px solid Gray;
background-color : #CCCCCC;
}
</style>
</head>
<body>
<center>
<h1>Domain and Whois lookup</h1>
<?php
$passcode = getPostVar('passcode');
$passval = getPostVar('passval');
if ($passcode != md5($passval))
{
echo "<h2>You need to enter the passcode</h2>";
$defext = getPostVar('ext');
$fail = true;
}
else $defext = 'XX';
?>
<form method="POST" action="index.php">
<b>www. <input type="text" size="20" name="host"> . </b>
<select size="1" name="ext">
<?PHP
foreach($masters as $ext => $whois)
{
$selected = ($defext == $ext)?' selected ':'';
echo "<option value='{$ext}'{$selected}>{$ext}</option>";
}
?>
</select>
<input type="submit" value="Whois" name='submit'>
<br>
<input type='text' name='ip'> <input type='submit' value='IP Check' name='submit'><br />
<?php
$rand = rand(1001, 9999);
$passcode = md5($rand);
echo "<input type='hidden' name='passcode' value='{$passcode}'>Type {$rand} here:
<input type='text' name='passval' value=''><br />";
?>
</form>
</center>
<?php
///////////////////////////////////////
// Logic Starts Here
///////////////////////////////////////
$button = getPostVar('submit');
if (!empty($button) && !$fail)
{
if ( $button == 'IP Check')
{
$ip = getPostVar('ip');
$hostname = trim(gethostbyaddr($ip));
if ($ip == $hostname)
{
//'whois -h whois.arin.net 66.249.65.166'
//'whois -h whois.radb.net 66.249.65.166'
echo "No hostname is available<br>";
echo requestWhois('whois.arin.net', $ip);
echo '<hr>';
echo requestWhois('whois.radb.net', $ip);
echo '<hr>';
$ext = '';
}
else
{
$hostrev = strrev($hostname);
$searching = true;
foreach ($masters as $test => $ipcheck)
{
if ($searching && (strrev($test) == substr($hostrev, 0, strlen($test))))
{
$searching = false;
$ext = $test;
$host = strrev( substr($hostrev, strlen($test)+1));
}
}
if ($searching) $ext = '';
}
}
else
{
$host = getPostVar('host');
$ext = getPostVar('ext');
$hostname = "{$host}.{$ext}";
}
if (!empty($ext) && isset($masters[$ext]))
{
$whois = $masters[$ext];
if (checkdnsrr($hostname) == 1)
{
echo '<h2>Registration Information for: http://www.'.$hostname.'</h2>';
if (!empty($hostname)) echo requestWhois($whois, $hostname);
}
else echo '<h2>http://www.'.$hostname.' may be free to register</h2>';
}
else echo "<h2><b>{$ext}</b> is an unknown file extension</h2>";
}
?>
</body>
</html> | | |
|
| Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | Retrieve text from table and email to your e-
address in pipe delimited format. Categories : PHP, MySQL | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | PHP Script to find url links in a page Categories : PHP, URLs, Regexps, Arrays | | | Using $PHP_AUTH_USER and $PHP_AUTH_PW to authenticate. Categories : Authentication, PHP | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | Function to remember password Categories : PHP, Authentication, Personalization and Membership | | | Create Thumbnails - resize an image - jpeg, jpg, gif, png to the specifed width and height in proportion without loosing out on pixcel quality. Categories : PHP, GD image library, Graphics | | | readline -- Reads a line Categories : PHP, PHP Functions, Readline | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Math operations on big numbers Categories : PHP, Math. | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | |
| | | | Joseph Crawford wrote :1192
Pretty nice example. I like to see stuff like this posted, once good chore would be to make this object oriented and use a template system, maybe this is something i will work out ;)
Joe Crawford
weberdev@codebowl.com
| |
|
|
|