<<携帯ミュージックプレイヤー>> |
個人輸入>>
2006年09月05日
送信元が中国からのメールを拒否するルール
こちらを参考に中国からのメールを拒否するルールを生成するphpスクリプトを作成してみました。
$target = "http://ftp.apnic.net/stats/apnic/delegated-apnic-latest";
$fp = fopen($target, "r");
while (!feof ($fp)) {
$line = trim(fgets($fp));
if(preg_match('/^apnic\|CN\|ipv4\|([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})\|(\d+)\|\d+\|allocated$/', $line, $matches)) {
$host_number = (int) $matches[5] - 1;
$maskhex= sprintf('%08s', dechex($host_number));
for ($i=0; $i<=3; $i++) {
$ip[$i] = $matches[$i+1];
$mask[$i] = hexdec(substr($maskhex, $i*2, 2));
}
if ($mask[0] == 0) {
$out = $ip[0].'.';
} else {
$out = sprintf('%d-%d.', $ip[0], $ip[0]+$mask[0]);
}
if ($mask[1] == 0) {
$out .= $ip[1].'.';
} elseif ($mask[1] == 255) {
$out .= '.';
} else {
$out .= sprintf('%d-%d.', $ip[1], $ip[1]+$mask[1]);
}
if ($mask[2] == 0) {
$out .= $ip[2].'.';
} elseif ($mask[2] != 255) {
$out .= sprintf('%d-%d.', $ip[2], $ip[2]+$mask[2]);
}
echo "$out:deny\r\n";
}
}
fclose ($fp);
?>
$fp = fopen($target, "r");
while (!feof ($fp)) {
$line = trim(fgets($fp));
if(preg_match('/^apnic\|CN\|ipv4\|([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})\.([0-9]{1,4})\|(\d+)\|\d+\|allocated$/', $line, $matches)) {
$host_number = (int) $matches[5] - 1;
$maskhex= sprintf('%08s', dechex($host_number));
for ($i=0; $i<=3; $i++) {
$ip[$i] = $matches[$i+1];
$mask[$i] = hexdec(substr($maskhex, $i*2, 2));
}
if ($mask[0] == 0) {
$out = $ip[0].'.';
} else {
$out = sprintf('%d-%d.', $ip[0], $ip[0]+$mask[0]);
}
if ($mask[1] == 0) {
$out .= $ip[1].'.';
} elseif ($mask[1] == 255) {
$out .= '.';
} else {
$out .= sprintf('%d-%d.', $ip[1], $ip[1]+$mask[1]);
}
if ($mask[2] == 0) {
$out .= $ip[2].'.';
} elseif ($mask[2] != 255) {
$out .= sprintf('%d-%d.', $ip[2], $ip[2]+$mask[2]);
}
echo "$out:deny\r\n";
}
}
fclose ($fp);
?>
コメント
おぉ!!
綺麗に作り直していただいて感謝です。
今はqmailからpostfixに乗り換えてしまいました。
が、同様の事をipfilterで行なっています。
綺麗に作り直していただいて感謝です。
今はqmailからpostfixに乗り換えてしまいました。
が、同様の事をipfilterで行なっています。
Posted by GALE at 2006年09月06日 01:40 午前)
<<携帯ミュージックプレイヤー>> |
個人輸入>>

