原来写的IPwhois类
1
2/*
3*
4* Class : IP Whois Verson 1.0
5* Info : Get IP's information form 4 whois server
6* Author : PhpUp Studio
7* Date : 12/12/2004
8* www.knowsky.com
9*
10*/
11class IPWhois
12{
13var $server = 'whois.arin.net';
14var $target;
15var $timeout = 10;
16var $msg;
17
18function IPWhois($target)
19{
20$this->target = $target;
21}
22function ShowInfo()
23{
24if($this->_CheckIP($this->target))
25{
26$this->msg = $this->_GetInfo($this->server);
27if($this->_CheckInfo($this->msg))
28{
29$this->msg = $this->_GetInfo($this->server);
30}
31}
32else $this->msg = '
<p>Please Enter An IP Address<br/></p>
1';
2
3return $this->msg;
4}
5function _CheckIP($temptarget)
6{
7if(eregi("[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}", $temptarget))
8{
9$f = 1;
10$detail = explode(".",$temptarget);
11foreach($detail as $v)
12{
13if($v > 255 || $v < 0)
14{
15$f = 0;
16break;
17}
18}
19}
20else $f =0;
21return $f;
22}
23function _GetInfo($tempserver)
24{
25$this->msg = '';
26
27if(!$sock = fsockopen($tempserver, 43, $num, $error, $this->timeout))
28{
29unset($sock);
30$this->msg = "Timed-out connecting to $tempserver (port 43)";
31}
32else
33{
34fputs($sock, "$this->target\n");
35$this->msg .= "
<p>IP Whois Information For <b>".$this->target."</b><br/><br/>";
$this->msg .= "-----------------------------------------------------------------<br/>";
while (!feof($sock))
$this->msg .= fgets($sock, 10240);
$this->msg .= "-----------------------------------------------------------------<br/></p>
1";
2}
3fclose($sock);
4return nl2br($this->msg);
5}
6function _CheckInfo($tempmsg)
7{
8if(eregi("whois.ripe.net", $tempmsg))
9{
10$this->server = "whois.ripe.net";
11return 1;
12}
13elseif(eregi("whois.apnic.net", $tempmsg))
14{
15$this->server = "whois.apnic.net";
16return 1;
17}
18elseif(eregi("whois.lacnic.net", $tempmsg))
19{
20$this->server = "whois.lacnic.net";
21return 1;
22}
23else return 0;
24}
25}
调用
1
2include './class.php';
3$target = isset($_GET['ip'])?gethostbyname($_GET['ip']):'NULL';
4if('NULL' == $target || '' == $target)$result = '
<p>Please Input An IP Address<br/></p>
1';
2else
3{
4$whois = new IPWhois($target);
5//$result = "IP Whois Information For
<b>".$_POST['ip']."</b>
<br/>
<br/>
1";
2$result = $whois->ShowInfo();
3}
4echo $result;