<?
$file="ip.txt";
$ip=$_SERVER['REMOTE_ADDR'];
$handle=fopen($file,'a');
fwrite($handle,"IP Address:");
fwrite($handle,"$ip");
fwrite($handle,"\n");
fclose($handle);
?>

附:.htaccess屏蔽IP段方法

Deny from 192.168.1