一聚教程网:一个值得你收藏的教程网站

热门教程

php天气小偷程序,可自动识别IP地址

时间:2022-11-14 23:01:46 编辑:袖梨 来源:一聚教程网

tp.php 文件:

/*

tq 天气

qs 趋势

rq 日期

wd 温度

fx 风向

address 地址

qq 805830

*/

include_once('./include/tq/function.inc.php');

$staid = sta_id();

$ip = getIp();

//$address = convertip($ip);

$address = addr();

echo $address." ";

function open($file,$type=''){

if($open=file($file)){

$count=count($open);

for($i=0;$i<$count;$i++){

$theget.=$open[$i];

}

}else{

die('请求过多,超时,请刷新');

}

return $theget;

}

$_str = open('http://www.weathercn.com/tqyb/detail.jsp?sta_id='.$staid);

//echo $_str;

/**

变量说明:

$str 要进行操作的字符串;

$split 拆分目标字符(串);

$from_no 从第几个开始;

$desc_y_n 顺取(〉0的值)还是倒取(0);

*/

//$_str = "aaa .1..aaa.2..aaa .3..aaa.4..aaa.5..bbb..7.bbb.8..bbb.9..bbb.10..bbb";

$split_a = "中国气象局";

$split_b = "时至";

$str_b = strstr($_str,$split_b);//寻找$split_b第一次出现的位置

$str_a = substr($_str,0,strpos($_str, $split_b));//可以取得字符串的指定长度子字符串

function _getStr_from_to($str,$split,$from_no,$desc_y_n)

{

$arr = explode($split,$str);

$size = sizeof($arr);

$from_no = ($from_no<=$size) ? $from_no : $size;

unset($_tmp_out_str);

if($desc_y_n)

{

//正序

for($i=$from_no;$i<$size;$i++)

{

$_tmp_out_str .= $split.$arr[$i];

}

}

else

{

$_tmp_from = $size - $from_no;

for($i=0;$i<$_tmp_from;$i++)

{

$_tmp_out_str .= $arr[$i].$split;

}

}

return $_tmp_out_str;

}

$srting = _getStr_from_to($str_a,"中国气象局",1,1);

//echo $srting;

preg_match_all('/alt="([^"]*)"/',$srting,$tq);

$tq = $tq[1];

if (is_array($tq))

$tq = implode('转',$tq);

//print_r($tq);

echo $tq." ";

preg_match_all('/([0-9-]*℃)~([0-9-]*℃)/',$srting,$wd);

$wd = $wd[0];

$wd = $wd[0];

print_r($wd);

?>
复制代码function.inc.php 文件

// 获取用户IP地址

function getIp() {

if($_SERVER['HTTP_CLIENT_IP'])

{

return $_SERVER['HTTP_CLIENT_IP'];

} elseif ($_SERVER['HTTP_X_FORWARDED_FOR']) {

return $_SERVER['HTTP_X_FORWARDED_FOR'];

} else {

return $_SERVER['REMOTE_ADDR'];

}

}

function getFile($url)

{

if($f=fopen("$url","r"))

{

while(!feof($f))

{

$s.=fgets($f);

}

fclose($f);

return $s;

} else {

return false;

}

}

function putFile($file_name,$file_string)

{

if($f=fopen($file_name,"w"))

{

fwrite($f, $file_string);

}

fclose($f);

}

function cnSubStr($string,$sublen) {

if($sublen>=strlen($string)){

return $string;

}

$s="";

for($i=0;$i<$sublen;$i++){

if(ord($string{$i})>127){

$s.=$string{$i}.$string{++$i};

continue;

}else{

$s.=$string{$i};

continue;

}

}

return $s."...";

}

function getPageBar($count = 0)

{

$bad_link_color = "#C0C0C0";

$page["url"] = eregi_replace("&page=[^&]+","",basename($_SERVER[SCRIPT_NAME])."?".$_SERVER[QUERY_STRING]);

$page["result_count"] = (string) $count;

$page["this_page"] = (empty($_GET["page"]))?"1":$_GET["page"];

$page["this_page"] = ($page["result_count"] == 0)?"0":$page["this_page"];

$page["page_size"] = $GLOBALS["option"]["page_size"];

$page["page_count"] = (string) ceil($page["result_count"]/$page["page_size"]);

$page["first_page"] = ($page["this_page"] > 1)?"«":"";

$page["rearward_page"] = ($page["this_page"] < (int) $page["page_count"])?"»":"";

$page["prev_page"] = ($page["this_page"] > 1)?"":"";

$page["next_page"] = ($page["this_page"] < (int) $page["page_count"])?"":"";

$page['start_page'] = ((int)$page["this_page"]-5<1)?1:(int)$page["this_page"]-5;

$page['end_page'] = ((int)$page["this_page"]+5 > $page['page_count'])?(int)$page["page_count"]:(int)$page["this_page"]+5;

for ($i = $page['start_page'];$i <= $page['end_page'];$i++)

{

$selected = ($_GET["page"] == $i)?"selected":"";

$page["page_select"] .= "";

$page["page_list"] .= ($i == $page["this_page"])?" $i ":"[$i]";

}

return $page;

}

function getRows($table,$order='')

{

if (!empty($order))

{

$order = explode(',',$order);

$order = 'ORDER BY `'.$order[0].'` '.$order[1];

}

$query = dbQuery("SELECT * FROM `".$GLOBALS['prefix'].$table."` ".$order.";");

while ($row = dbArray($query))

{

$link[$row['id']] = $row;

}

return $link;

}

function autoTime($time)

{

preg_match('/([0-9]*)-([0-9]*)-([0-9]*) ([0-9]*):([0-9]*):([0-9]*)/',$time,$date);

return mktime ($date[4],$date[5],$date[6],$date[2],$date[3],$date[1]);

}

function getTime() {

$t = explode(' ', microtime());

return $t[1] + $t[0];

}

function calendar($time)

{

$start = mktime(0, 0, 0, date('m', $time), 1, date('Y', $time));

$prev_month['year'] = date('Y',$start-86400);

$prev_month['month'] = date('m',$start-86400);

$end = mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));

$next_month['year'] = date('Y',$end);

$next_month['month'] = date('m',$end);

$sWeekday=array('日','一','二','三','四','五','六');

//$sWeekday=array('S','M','T','W','T','F','S');

$title=date('M Y', $time);

$str = '';

$str .= <<

END;

$year = (empty($_GET['year']))?date('Y'):$_GET['year'];

$month = (empty($_GET['month']))?date('m'):$_GET['month'];

$query = dbQuery("SELECT FROM_UNIXTIME(date,'%e') as `day`,count(*) as `count` FROM `".$GLOBALS['prefix']."article`,`".$GLOBALS['prefix']."article_class` WHERE FROM_UNIXTIME(date,'%Y/%m') = '".$year."/".$month."' AND `status` = 'published' AND ".$GLOBALS['prefix']."article.class_id = ".$GLOBALS['prefix']."article_class.id AND `in_main_page` = 1 GROUP BY `day`;");

for ($i = 0;$i < mysql_num_rows($query);$i++)

{

$row = dbArray($query);

$calendar[$row['day']] = $row['count'];

}

for ($i = 0;$i < date('w',$start);$i++)

{

$str.= '

';

}

for($stamp=$start;$stamp<$end;$stamp+=86400) // loop through each day, which is 86400 seconds

{

$weekday=date('w', $stamp);

$day = date('d', $stamp);

if(date('Y-m-d', $stamp)==date('Y-m-d')) $style='today';

else if(date('w', $stamp)==0 || date('w', $stamp)==6) $style='weekend';

else $style='weekday';

$str.= " ".'

'." ";

if(date('w', $stamp)==6) $str.=" ".'

'." ";

}

$str .= '

«

{$title}

»

{$sWeekday[0]}

{$sWeekday[1]}

{$sWeekday[2]}

{$sWeekday[3]}

{$sWeekday[4]}

{$sWeekday[5]}

{$sWeekday[6]}

';

$str.= ($calendar[date('j', $stamp)] > 0)?''.(int)$day.'':(int)$day;

$str.= '

';

return $str;

}

//php利用纯真ip数据库查地址的函数

function convertip($ip) {

if(!preg_match("/^d{1,3}.d{1,3}.d{1,3}.d{1,3}$/", $ip)) {

return '';

}

if($fd = @fopen( "e:hostswkhddbipdatawry.dat", 'rb')) {//fopen()中是纯真ip数据库文件位置,请自行设定!

$ip = explode('.', $ip);

$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];

$DataBegin = fread($fd, 4);

$DataEnd = fread($fd, 4);

$ipbegin = implode('', unpack('L', $DataBegin));

if($ipbegin < 0) $ipbegin += pow(2, 32);

$ipend = implode('', unpack('L', $DataEnd));

if($ipend < 0) $ipend += pow(2, 32);

$ipAllNum = ($ipend - $ipbegin) / 7 + 1;

$BeginNum = 0;

$EndNum = $ipAllNum;

while($ip1num > $ipNum || $ip2num < $ipNum) {

$Middle= intval(($EndNum + $BeginNum) / 2);

fseek($fd, $ipbegin + 7 * $Middle);

$ipData1 = fread($fd, 4);

if(strlen($ipData1) < 4) {

fclose($fd);

return '系统错误';

}

$ip1num = implode('', unpack('L', $ipData1));

if($ip1num < 0) $ip1num += pow(2, 32);

if($ip1num > $ipNum) {

$EndNum = $Middle;

continue;

}

$DataSeek = fread($fd, 3);

if(strlen($DataSeek) < 3) {

fclose($fd);

return '系统错误';

}

$DataSeek = implode('', unpack('L', $DataSeek.chr(0)));

fseek($fd, $DataSeek);

$ipData2 = fread($fd, 4);

if(strlen($ipData2) < 4) {

fclose($fd);

return 'System Error';

}

$ip2num = implode('', unpack('L', $ipData2));

if($ip2num < 0) $ip2num += pow(2, 32);

if($ip2num < $ipNum) {

if($Middle == $BeginNum) {

fclose($fd);

return 'Unknown';

}

$BeginNum = $Middle;

}

}

$ipFlag = fread($fd, 1);

if($ipFlag == chr(1)) {

$ipSeek = fread($fd, 3);

if(strlen($ipSeek) < 3) {

fclose($fd);

return '系统错误';

}

$ipSeek = implode('', unpack('L', $ipSeek.chr(0)));

fseek($fd, $ipSeek);

$ipFlag = fread($fd, 1);

}

if($ipFlag == chr(2)) {

$AddrSeek = fread($fd, 3);

if(strlen($AddrSeek) < 3) {

fclose($fd);

return 'System Error';

}

$ipFlag = fread($fd, 1);

if($ipFlag == chr(2)) {

$AddrSeek2 = fread($fd, 3);

if(strlen($AddrSeek2) < 3) {

fclose($fd);

return 'System Error';

}

$AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));

fseek($fd, $AddrSeek2);

} else {

fseek($fd, -1, SEEK_CUR);

}

while(($char = fread($fd, 1)) != chr(0))

$ipAddr2 .= $char;

$AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));

fseek($fd, $AddrSeek);

while(($char = fread($fd, 1)) != chr(0))

$ipAddr1 .= $char;

} else {

fseek($fd, -1, SEEK_CUR);

while(($char = fread($fd, 1)) != chr(0))

$ipAddr1 .= $char;

$ipFlag = fread($fd, 1);

if($ipFlag == chr(2)) {

$AddrSeek2 = fread($fd, 3);

if(strlen($AddrSeek2) < 3) {

fclose($fd);

return 'System Error';

}

$AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));

fseek($fd, $AddrSeek2);

} else {

fseek($fd, -1, SEEK_CUR);

}

while(($char = fread($fd, 1)) != chr(0))

$ipAddr2 .= $char;

}

fclose($fd);

if(preg_match('/http/i', $ipAddr2)) {

$ipAddr2 = '';

}

$ipaddr = "$ipAddr1"; // 完整地址为 "$ipAddr1 $ipAddr2"

$ipaddr = preg_replace('/CZ88.NET/is', '', $ipaddr);

$ipaddr = preg_replace('/^s*/is', '', $ipaddr);

$ipaddr = preg_replace('/s*$/is', '', $ipaddr);

if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {

$ipaddr = 'Unknown';

}

return $ipaddr;

} else {

$datadir = PHPCMS_ROOT.'./ipdata/';

$ip_detail = explode('.', $ip);

if(file_exists($datadir.$ip_detail[0].'.txt')) {

$ip_fdata = @fopen($datadir.$ip_detail[0].'.txt', 'r');

} else {

if(!($ip_fdata = @fopen($datadir.'0.txt', 'r'))) {

return 'Invalid IP data file';

}

}

for ($i = 0; $i <= 3; $i++) {

$ip_detail[$i] = sprintf('%03d', $ip_detail[$i]);

}

$ip = join('.', $ip_detail);

do {

$ip_data = fgets($ip_fdata, 200);

$ip_data_detail = explode('|', $ip_data);

if($ip >= $ip_data_detail[0] && $ip <= $ip_data_detail[1]) {

fclose($ip_fdata);

return $ip_data_detail[2].$ip_data_detail[3];

}

} while(!feof($ip_fdata));

fclose($ip_fdata);

return '未知地址';

}

}

// station_id 函数

function sta_id(){

include_once('./include/tq/config.inc.php');

include_once('./include/tq/error.inc.php');

include_once('./include/tq/mysql.inc.php');

include_once('./include/tq/template.inc.php');

unset($onlineip);

if($_SERVER['HTTP_CLIENT_IP']){

$onlineip=$_SERVER['HTTP_CLIENT_IP'];

}elseif($_SERVER['HTTP_X_FORWARDED_FOR']){

$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];

}else{

$onlineip=$_SERVER['REMOTE_ADDR'];

}

$ips = $onlineip;

$addr = convertip($ips);

$address = $addr;

$address = str_replace(array('省','市','县','工业','北京','区','大学','武汉','西安','安交','海交','新疆','大连','广西'),array(' ',' ',' ',' 工业','北京 ',' ',' ','武汉 ','西安 ','安 交','海 交','新疆 ','大连 ','广西 '),$address);

$addresss = explode(" ",$address);

$address1 = $addresss[0];

$address2 = $addresss[1];

$address3 = $addresss[2];

$address4 = $addresss[3];

$query = dbQuery("select count(*) as num from ".weather_station." where province like '$address1' ");//查询 省字段 数目

$row = dbArray($query);

$number = $row["num"];

if($number>0 && $address2<>'' && $address1<>上海 && $address1<>重庆){

unset($addresss[0]);

}

if($address4==''){

unset($addresss[3]);

}

if($address3==''){

unset($addresss[2]);

}

$query = dbQuery("select count(*) as num from ".weather_station." where station like '$address4' ");//查询 县 字段

$row = dbArray($query);

$number = $row["num"];

if($number==0){

unset($addresss[3]);

}

$query = dbQuery("select count(*) as num from ".weather_station." where station like '$address3' ");//查询 县 字段

$row = dbArray($query);

$number = $row["num"];

if($number==0){

unset($addresss[2]);

}

//数组数据2 查询开始

$queryx = dbQuery("select count(*) as nums from ".weather_station." where station like '$address2' ");//查询 县 字段

$row = dbArray($queryx);

$nums = $row["nums"];

$queryy = dbQuery("select count(*) as numd from ".weather_station." where district like '$address2' ");//查询 市 字段

$row = dbArray($queryy);

$numd = $row["numy"];

if($nums==0 && $numd==0){

unset($addresss[1]); // 如果 数组数据2 不在数据库里则删除数据2

}

//数组数据2 查询结束

$query = dbQuery("select count(*) as num from ".weather_station." where district like '$address2' ");//查询 市 字段

$row = dbArray($query);

$number = $row["num"];

if($number>1 && $address3<>'' && $nums<>0 && $address2<>广州 ){

unset($addresss[1]); // 如果数组数据2在数据库里有 多个 则删除数据2

}

@extract(dbQuery("select count(*) as num_0 from ".weather_station." where district like '$address1' "));//查询 市 字段

@extract(dbQuery("select count(*) as num_1 from ".weather_station." where station like '$address2' "));//查询 县 字段

$number = $num_0;

$numbery = $num_1;

if($number>1 && $numbery>0 && $address2<>''){

unset($addresss[0]); //如果数组数据1在数据库里有 多个 则删除数据1

}

$addresss = implode("",$addresss);

//字符串处理完毕 下面开始查询 station_id

$query1 = dbQuery("select count(*) as nums_addresss from ".weather_station." where station like '$addresss' ");

$row1 = dbArray($query1);

$nums_addresss = $row1["nums_addresss"];

$query2 = dbQuery("select count(*) as numd_addresss from ".weather_station." where district like '$addresss' ");

$row2 = dbArray($query2);

$numd_addresss = $row2["numd_addresss"];

if($nums_addresss>0){

$result = dbQuery("SELECT station_id FROM ".weather_station." WHERE station like '$addresss' ORDER BY id");

$r = dbArray($result);

$station_id[] = $r[station_id];

$station_id = $station_id[0];

return $station_id; // 查询结果

}

if($nums_addresss==0 && $numd_addresss>0){

$result = dbQuery("SELECT station_id FROM ".weather_station." WHERE district like '$addresss' ORDER BY id");

$r = dbArray($result);

$station_id[] = $r[station_id];

$station_id = $station_id[0];

return $station_id; // 查询结果

//echo $station_id;

}

}

function get_real_ip()

{

$ip=false;

if(!empty($_SERVER["HTTP_CLIENT_IP"]))

{

$ip = $_SERVER["HTTP_CLIENT_IP"];

}

if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))

{

$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);

if ($ip)

{

array_unshift($ips, $ip); $ip = FALSE;

}

for ($i = 0; $i < count($ips); $i++)

{

if (!eregi ("^(10|172.16|192.168).", $ips[$i]))

{

$ip = $ips[$i];

break;

}

}

}

return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);

}

function addr(){

include_once('./include/tq/config.inc.php');

include_once('./include/tq/error.inc.php');

include_once('./include/tq/mysql.inc.php');

include_once('./include/tq/template.inc.php');

unset($onlineip);

if($_SERVER['HTTP_CLIENT_IP']){

$onlineip=$_SERVER['HTTP_CLIENT_IP'];

}elseif($_SERVER['HTTP_X_FORWARDED_FOR']){

$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];

}else{

$onlineip=$_SERVER['REMOTE_ADDR'];

}

$ips = $onlineip;

$addr = convertip($ips);

$address = $addr;

$address = str_replace(array('省','市','县','工业','北京','区','大学','武汉','西安','安交','海交','新疆','大连','广西'),array(' ',' ',' ',' 工业','北京 ',' ',' ','武汉 ','西安 ','安 交','海 交','新疆 ','大连 ','广西 '),$address);

$addresss = explode(" ",$address);

$address1 = $addresss[0];

$address2 = $addresss[1];

$address3 = $addresss[2];

$address4 = $addresss[3];

$query = dbQuery("select count(*) as num from ".weather_station." where province like '$address1' ");//查询 省字段 数目

$row = dbArray($query);

$number = $row["num"];

if($number>0 && $address2<>'' && $address1<>上海 && $address1<>重庆){

unset($addresss[0]);

}

if($address4==''){

unset($addresss[3]);

}

if($address3==''){

unset($addresss[2]);

}

$query = dbQuery("select count(*) as num from ".weather_station." where station like '$address4' ");//查询 县 字段

$row = dbArray($query);

$number = $row["num"];

if($number==0){

unset($addresss[3]);

}

$query = dbQuery("select count(*) as num from ".weather_station." where station like '$address3' ");//查询 县 字段

$row = dbArray($query);

$number = $row["num"];

if($number==0){

unset($addresss[2]);

}

//数组数据2 查询开始

$queryx = dbQuery("select count(*) as nums from ".weather_station." where station like '$address2' ");//查询 县 字段

$row = dbArray($queryx);

$nums = $row["nums"];

$queryy = dbQuery("select count(*) as numd from ".weather_station." where district like '$address2' ");//查询 市 字段

$row = dbArray($queryy);

$numd = $row["numy"];

if($nums==0 && $numd==0){

unset($addresss[1]); // 如果 数组数据2 不在数据库里则删除数据2

}

//数组数据2 查询结束

$query = dbQuery("select count(*) as num from ".weather_station." where district like '$address2' ");//查询 市 字段

$row = dbArray($query);

$number = $row["num"];

if($number>1 && $address3<>'' && $nums<>0 && $address2<>广州 ){

unset($addresss[1]); // 如果数组数据2在数据库里有 多个 则删除数据2

}

@extract(dbQuery("select count(*) as num_0 from ".weather_station." where district like '$address1' "));//查询 市 字段

@extract(dbQuery("select count(*) as num_1 from ".weather_station." where station like '$address2' "));//查询 县 字段

$number = $num_0;

$numbery = $num_1;

if($number>1 && $numbery>0 && $address2<>''){

unset($addresss[0]); //如果数组数据1在数据库里有 多个 则删除数据1

}

$addresss = implode("",$addresss);

return $addresss; // 结果

}

?>
复制代码config.inc.php

// this file is mysql config

$dbhost = 'localhost';

$dbname = '********';

$dbuser = '********';

$dbpass = '******';

$prefix = '';

?>

热门栏目