利用bootstrap框架二次开发了ip查询的页面..
ip查询是基于淘宝API的函数...
域名whois查询,我是接入站长之家的...
新手做站.难免代码复杂...
效果请点击ip查询
以下是代码
<?php header("content-Type: text/html; charset=utf-8");$weburl=$_SERVER['SERVER_NAME'];$weblink="http://".$weburl."/";if(count($_GET)>0){$urlip=array_keys($_GET);$urlip=str_replace("_",".",$urlip[0]);}?> <!DOCTYPE > <html> <head> <meta charset="UTF-8"> <title><?=$urlip;?><?=$_POST['ip'];?>IP查询</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <link type="image/vnd.microsoft.icon" href="img/favicon.png" rel="shortcut icon"> <script src="http://apps.bdimg.com/libs/jquery/2.0.0/jquery.min.js"></script> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" > <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script language="JavaScript"> function checkIP(){ var ipArray,ip,j;ip = document.ipform.ip.value; if(/[A-Za-z_-]/.test(ip)){if(!/^([\w-]+\.)+((com)|(net)|(org)|(gov\.cn)|(info)|(cc)|(com\.cn)|(com\.hk)|(net\.cn)|(org\.cn)|(com\.ru)|(net\.ru)|(org\.ru)|(name)|(biz)|(hk)|(vn)|(com\.sg)|(pk)|(ph)|(ac)|(bz)|(de)|(net\.au)|(my)|(tv)|(us)|(jp)|(kr)|(sg)|(mn)|(cd)|(ue)|(sh)|(lc)|(hn)|(me)|(la)|(cc)|(tk)|(com\.tw)|(cm)|(cn)|(top)|(club)|(xin)|(xyz)|(shop)|(wang)|(site)|(vip)|(store)|(bid)|(ltd)|(ren)|(lol)|(online)|(tech)|(asia))$/.test(ip)){alert("不是正确的域名,请检查域名格式或看是否有空格"); document.ipform.ip.focus();return false;}}else{ipArray = ip.split(".");j = ipArray.length;if(j!=4){alert("不是正确的IP"); document.ipform.ip.focus();return false;}for(var i=0;i<4;i++){if(ipArray[i].length==0 || ipArray[i]>255){alert("不是正确的IP"); document.ipform.ip.focus(); return false;}}}} </script> <body> <?php $ip=$_POST['ip']?$_POST['ip']:$urlip;if(!$ip)$ip=get_real_ip(); $ip=preg_match('/((\w|-)+\.)+[a-z]{2,4}/i',$ip)?gethostbyname($ip) : $ip; $ipdata=ipdata($ip,'all'); ?> <div class="jumbotron"> <div class="container" align="center"> <h2 class="text-info" style="font-family:宋体;font-weight:bold;font-size:49px"><a href="https://199604.com/ip" title="IP查询" target="_blank">IP查询</a></h2> <br> <div class="text-muted"> <form action="" method="post" name="ipform" onsubmit="checkIP();"> <span class="text-primary">IP地址或域名(不带http/https):</span> <input type="text" name="ip" size="27" maxlength="100" title="<?=$weburl;?>提醒您在此输入ip或域名" id="url" value="<?php if(!$_POST['ip']){echo $urlip;}else{echo $_POST['ip'];}?>"> <input type="submit" value="查 询" id="sub" class="btn btn-primary btn-xs"><input type="hidden" name="action" value="2"></p> </form> <?php if(is_ip($ip)){ $ipaddress=$ipdata->country; if($ipdata->region==$ipdata->city){$ipaddress.=$ipdata->city;}else{$ipaddress.=$ipdata->region.$ipdata->city;} $ipaddress.=$ipdata->isp; echo "您查询的IP: [<a href='http://ip.chinaz.com/".$ip."'><font color=#FF0000>".$ip."</font></a>]<br/>IP详细地址: [<font color=#FF0000>".$ipaddress."</font>]<br/>"; }else{echo "囧,你输入的IP,居然不能查询到!不是输入错误?";} $ipdaili=$_SERVER['REMOTE_ADDR']; if(!in_array($ipdaili,array('127.0.0.1',$ip,$_SERVER['SERVER_ADDR'],get_real_ip()))){ echo "您的代理IP是[<a href='http://ip.chinaz.com/".$ipdaili."'><font color=#FF0000>".$ipdaili."</font></a>]<br/>来自".ipdata($ipdaili).""; } $whiosip=$_POST['ip']?$_POST['ip']:$urlip; if($whiosip){preg_match('/((\w|-)+\.)+[a-z]{2,4}/i',$whiosip) ? $whois=str_replace("www.","",$whiosip):"";} if($whois){echo "<br /><br /><a href='http://whois.chinaz.com/".$whois."' target='_blank'>点击查看域名 ".$whois." 的WhoIs信息</a>";} ?> </div> <table class="table table-hover table-bordered"> <thead> <th>IP</th> <th>国家/地区</th> <th>省份</th> <th>城市</th> <th>县</th> <th>运营商</th> </thead> <tbody> <tr> <td class="text-primary"><span class="sip"><?=$ip;?></span></td> <td class="text-primary"><?=$ipdata->country.$ipdata->area?></td> <td class="text-primary"><?=$ipdata->region?></td> <td class="text-primary"><?=$ipdata->city?></td> <td class="text-primary"><?=$ipdata->county?></td> <td class="text-primary"><?=$ipdata->isp?></td> </tr> </tbody> </table> <p>Copyright © 2012-<?php echo date("Y")?> <a href="https://199604.com" target="_blank" data-toggle="tooltip" title="记忆角落">记忆角落</a> All Rights Reserved</p> </div> </div> <script> $(function () { $("[data-toggle='tooltip']").tooltip(); }); </script> </body> </html> <?php function get_real_ip(){ if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {$ip = getenv('HTTP_CLIENT_IP');} elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {$ip = getenv('HTTP_X_FORWARDED_FOR');} elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {$ip = getenv('REMOTE_ADDR');} elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {$ip = $_SERVER['REMOTE_ADDR'];} return preg_match("/[\d\.]{7,15}/", $ip, $matches) ? $matches[0] : false; } function is_ip($str) { $ip = explode(".", $str);if (count($ip)<4 || count($ip)>4) return 0; foreach($ip as $ip_addr) {if ( !is_numeric($ip_addr) ) return 0;if ( $ip_addr<0 || $ip_addr>255 ) return 0; }return 1; } function ipdata($ip,$name="0") { $url="http://ip.taobao.com/service/getIpInfo.php?ip="; $data=json_decode(file_get_contents($url.$ip)); $ipdata=$data->data; if($name=="all") {return $ipdata;} else if($name=="0"){return $ipdata->country.$ipdata->region.$ipdata->city.$ipdata->isp;} else if($name=="1"){return $ipdata->country;} else if($name=="2"){return $ipdata->area;} else if($name=="3"){return $ipdata->region;} else if($name=="4"){return $ipdata->city;} else if($name=="5"){return $ipdata->county;} else if($name=="6"){return $ipdata->isp;} } ?>