WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : DNS and Whois Lookup - allows you to quickly find information about a url or ip address
Categories : PHP Click here to Update Your Picture
Sarah King
Date : Sep 22nd 2004
Grade : 3 of 5 (graded 10 times)
Viewed : 16059
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

Submit your own code examples  Submit your own code examples 
 

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
Udm_Add_Search_Limit -- Add various search limits
Categories : PHP, PHP Functions, mnoGoSearch
PageRank Display
Categories : Search Engines, HTML and PHP, PHP
fforum fumanchi forum MySQL treestructure
Categories : Complete Programs, PHP, MySQL
A database abstraction layer for the PHP 3.0 ODBC module. It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, PHP, Complete Programs
A simple script to count and report hits and the last modification time of an HTML page. Requires MySQL support (other DBs should work too, except possibly mSQL).
Categories : HTTP, MySQL, PHP, Databases
GroupIT Engine v1.00rc1
Categories : PHP, Content Management, MySQL, Databases
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
How to find the name of the current file?
Categories : PHP, Filesystem, Strings
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Print out array key => value in colored HTML
Categories : PHP, Arrays, HTML and PHP
filepro -- read and verify the map file
Categories : PHP, PHP Functions, filePro
PHP Class to calculate Degrees Minutes Seconds to Decimal Degrees
Categories : PHP, PHP Classes, Geo Related, Beginner Guides
How to strip non-alpha characters from a string
Categories : Regexps, PHP
Email a user with out exposing email address
Categories : PHP, Databases, MySQL, Email
 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