kuangmin 发表于 2005 年 7 月 6 日 14:15:39

[PHP] 可显IP、显具体地址、显中文图片的源程序

jacker.php
<?php
function drawer($image, $string, $x, $y, $color)
{
 $fp = fopen("chs16.fon", "r"); //WIN98中,此文件在:\windows\command 下
 if (feof($fp))
 {
     fclose($fp);
     return 0;
 }
// gbk
 $strings = preg_split('/((?:[\\x80-\\xFF][\\x40-\\xFF])+)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE);
 $isch = false;
 for ($p = 0, $count = count($strings); $p < $count; $p ++)
 {
     if ($isch)
     {
     $string = $strings[$p];
     for ($i = 0, $l = strlen($string) - 1; $i < $l; $i += 2)
     {
     $qh = ord($string{$i}); // get ascii code
     $offset = (94 * ($qh - 0xA0 - 1) + (ord($string{$i + 1}) - 0xA0 - 1)) * 32;
     fseek($fp, $offset, SEEK_SET);
     $buffer = unpack('n*', fread($fp, 32));
     // $buffers[$offset] = $buffer;
     for ($yy = 1, $ypos = $y; $yy <= 16; $yy ++, $ypos ++)
     {
         $bits = $buffer[$yy];
         for ($xbit = 32768, $xpos = $x; $xbit > 0; $xbit >>= 1, $xpos ++)
         {
         if ($bits & $xbit)
         {
         imagesetpixel($image, $xpos, $ypos, $color);
         }
         }
     }
     $x += 16;
     }
     }
     else
     {
     imagestring($image, 12, $x, $y, $strings[$p], $color);
     $x += strlen($strings[$p]) * 9;
     }
     $isch = !$isch;
 }
 return 0;
}
?>

读IP文本文件的代码该文件存为:ip.php:
<?
$flag=0;
$ip_detail=explode(".",$_SERVER["REMOTE_ADDR"]);

if ($ip_detail<=61) {
 $ip_data_file=61;
}
elseif($ip_detail<=199) {
 $ip_data_file=199;
}
elseif($ip_detail<=217){
 $ip_data_file=217;
}
elseif($ip_detail==218){
 $ip_data_file=218;
}
else{
 $ip_data_file=255;
}

if (file_exists("ipdata/$ip_data_file.txt")) {
 $ip_fdata=fopen("ipdata/$ip_data_file.txt","r");
}
else {
 if(!($ip_fdata=fopen("/ipdata/0.txt","r"))) {
     die("IP 数据文件错误");
 }
}

for ($i=0; $i<=3; $i++) {
 $ip_detail[$i]=sprintf("%3d", $ip_detail[$i]);
}
while(!feof($ip_fdata)){
 $ip_data=fgets($ip_fdata,200);
 $ip_data_detail=substr($ip_data,32,strlen($ip_data)-33); //IP物理地址
 $test000=explode(".",substr($ip_data,0,16));
 $test001=explode(".",substr($ip_data,16,16));

 for($s=0;$s<=3;$s++){
     $ip0[$s]=sprintf("%3d",$test000[$s]);
     $ip1[$s]=sprintf("%3d",$test001[$s]);
 }

 if(join(".",$ip_detail)>=join(".",$ip0) and join(".",$ip_detail)<=join(".",$ip1)) {
     fclose($ip_fdata);
     $flag=1;
     break;
 }
}

if($flag==0){
 echo "未知地区"."<BR>".$flag;
}
?>
读一个图片文件命名为:ip.php
<?php
header ("Content-type: image/png"); //http头
require ("jacker.php");
require ("ip.php");
$image = @imagecreatefrompng ("logo.png"); // 载入图片
$black = imagecolorallocate ($image, 0, 0, 0); // 默认黑色背景
$white = imagecolorallocate ($image, 255, 255, 255); // 默认黑色背景

$system=show_system();
$browser=show_browser();
$ip=$_SERVER["REMOTE_ADDR"];
$homepage="http://www.123cha.com/bbs";

drawer($image,$system,90,360,$white);
drawer($image,$browser,90,378,$white);
drawer($image,$ip,90,396,$white); //输出IP地址
drawer($image,$ip_data_detail,90,414,$white);
drawer($image,$homepage,90,432,$white);

imagepng ($image); // 以png格式输出
// 也可以用imagejpeg($im);
// 或imagegif($im);
// 但后者,如果GD版本高于1.6,就不能用了。
imagedestroy ($image); // 结束,清楚所有占用的内存资源

function show_browser(){
 $b = $_SERVER['HTTP_USER_AGENT'];
 $ie50 = preg_match("/MSIE 5.0/i", $b);
 $ie55 = preg_match("/MSIE 5.5/i", $b);
 $ie60 = preg_match("/MSIE 6.0/i", $b);
 $opera = preg_match("/opera/i", $b);
 if ($ie40 == 1) {
     $browser = "MSIE4.0";
 } else if ($ie50 == 1) {
     $browser = "MSIE5.0";
 } else if ($ie55 == 1) {
     $browser = "MSIE5.5";
 } else if ($ie60 == 1) {
     $browser = "MSIE6.0";
 } else if ($opera == 1) {
     $browser = "Opera";
 } else {
     $browser = "n/a";
 }
return($browser);
}

function show_system(){
 $so = $_SERVER['HTTP_USER_AGENT'];
 $windowsxp = preg_match("/windows nt 5.1/i", $so);
 $windowsxp2 = preg_match("/windows xp/i", $so);
 $linux = preg_match("/linux/i", $so);
 $windowsme = preg_match("/win 9x 4.90/i", $so);
 $windowsme2 = preg_match("/windows me/i", $so);
 $windows2k = preg_match("/windows nt 5.0/i", $so);
 $windows2kb = preg_match("/windows 2000/i", $so);
 $windowsnt = preg_match("/windows nt 3.1/i", $so);
 $windowsnt2 = preg_match("/windows nt 3.5.0/i", $so);
 $windowsnt3 = preg_match("/windows nt 3.5.1/i", $so);
 $windowsnt4 = preg_match("/windows nt 4.0/i", $so);
 $windows98 = preg_match("/windows 98/i", $so);
 $windows95 = preg_match("/windows 95/i", $so);
 if ($windowsxp == 1 or $windowsxp2 == 1) {
     $sys = "Win XP";
 } else if ($linux == 1) {
     $sys = "Linux";
 } else if ($windowsme == 1 or $windowsme2 == 1) {
     $sys = "Win ME";
 } else if ($windows2k == 1 or $windows2kb == 1) {
     $sys = "Win 2000";
 } else if ($windowsnt == 1 or $windowsnt2 == 1 or $windowsnt3 == 1 or $windowsnt4 == 1) {
     $sys = "Win NT";
 } else if ($windows98 == 1 and $windowsme != 1) {
     $sys = "Win 98--怎么还用瘟酒吧啊";
 } else if ($windows95 == 1) {
     $sys = "Win 95--系统也太落后了吧";
 } else {
     $sys = "n/a";
 }
return($sys);
}
?>

msn 发表于 2005 年 7 月 6 日 14:17:44

謝~~存下

杨威利 发表于 2005 年 7 月 6 日 14:19:01

哈,昨天在MS那里看过,今天这个有什么特别之处么

engyou 发表于 2005 年 7 月 6 日 14:20:31

找了N久了~~~~~~~~~~~~~太感谢了~~~~~~~研究去了~~~~~~~

kokgog 发表于 2005 年 7 月 6 日 14:21:45

看过

可乐泡咖啡 发表于 2005 年 7 月 6 日 14:22:28

顶哦!不错哦

engyou 发表于 2005 年 7 月 6 日 14:49:50

读IP文本文件的代码该文件存为:ip.php:
读一个图片文件命名为:ip.php

是不是重复命名了~~~~

iyaner 发表于 2005 年 7 月 6 日 14:53:41

支持MM

香小子 发表于 2005 年 7 月 6 日 14:57:22

以后玩

金光 发表于 2005 年 7 月 6 日 15:11:38

不错。
页: [1] 2 3 4
查看完整版本: [PHP] 可显IP、显具体地址、显中文图片的源程序