Linux下镜像NOD32病毒库的脚本
以前在网上找到的一个升级NOD32病毒库的脚本,在使用过程中不断的对其进行修正,最终生成了这个版本,我个人认为比较满意,暂时符合我的要求。
注意:这个脚本不是我原创的,脚本的作者是soff,目前可以在http://www.52crack.com/blog/?action=show&id=226找到,我做了一点点修改而已:
#!/usr/bin/php -qESS Update (Windows; U; 32bit; VDB 5843; BPC 3.0.684.0; OS: 5.1.2600 SP 3.0 NT; CH 1.1; LNG 2052; x32c; UPD http://
<?
// author: soff
// Modified by: ELM
$LOCALDIR = '/home/nod32';
$WGET = '/usr/bin/wget';
$UNRAR = '/usr/bin/unrar';
$GREP = '/bin/grep';
$STRINGS = '/usr/bin/strings';
$UPDATE_SERVER = 'http://u20.eset.com';
$USER = 'AV-7009043';
$PASS = 'vu34kgnc4a';
$UA = "u20.eset.com/eset_upd; APP eav; BEO 1)";
$product = array (‘nod_upd’, ‘eset_upd’, ‘eset_upd/sky’, ‘eset_upd/pre’);
chdir($LOCALDIR);
//不下载的文件
$ignore = array(‘data0001′);
//需要额外下载的文件
#$list[] = “{$UPDATE_SERVER}/nod_upd/expire.rar”;
$list = array();
//下载update.ver & 并处理,生成需要下载的文件列表
foreach ( $product as $subdir ) {
exec(“$WGET -U ‘$UA’ -t 9 -T 9 -N -nH -nd -P {$LOCALDIR}/{$subdir} {$UPDATE_SERVER}/{$subdir}/update.ver”, $output, $ret);
if ($ret > 0) {
echo ‘Failed while downloading {$UPDATE_SERVER}/{$subdir}/update.ver.’;
}
exec(“$UNRAR x -o+ {$LOCALDIR}/{$subdir}/update.ver”, $output, $ret);
if ($ret > 0) {
echo ‘Failed while extracting {$LOCALDIR}/{$subdir}/update.ver.’;
}
$content = file_get_contents(‘update.ver’);
preg_match_all(“/file=(.+?)\n/ie”, $content, $matches);
preg_match_all(“/build=(.+?)\n/ie”, $content, $buildes);
preg_match_all(“/size=(.+?)\n/ie”, $content, $size);
foreach($matches[1] as $id => $match) {
$match = trim($match);
$last = substr($match, 0);
if ( !in_array($last, $ignore)) {
exec(“$STRINGS {$LOCALDIR}{$match} | $GREP \”^” . trim($buildes[0][$id]) . “\”\n” , $output, $ret);
//echo “File size:” . (int)$size[1][$id] . ” Real Size:” . filesize($LOCALDIR . $match) . “\n”;
if ( $ret != 0 || (int)$size[1][$id] > filesize($LOCALDIR . $match) ) $list[] = “{$UPDATE_SERVER}$match”;
}
}
} // for each product
//消重
$list = array_unique($list);
if (count($list) > 0 ) { //get list
//生成list.txt文件
foreach ($list as $url) {
if ( strlen($url) > 10 )
$filelist .= $url . “\n”;
}
//写入到文件中,我这个机器上的php不支持file_put_contents函数,所以用比较笨的办法
#file_put_contents(‘list.txt’, $list);
$filename=”list.txt”;
if (!$handle = fopen($filename, ‘w’)) {
echo “不能打开文件 $filename”;
exit;
}
// 将$somecontent写入到我们打开的文件中。
if (fwrite($handle, $filelist) === FALSE) {
echo “不能写入到文件 $filename”;
exit;
}
fclose($handle);
//开始下载啦
exec(“$WGET –http-user=$USER –http-passwd=$PASS -U ‘$UA’ -t 9 -T 9 -m -nH -P $LOCALDIR -i list.txt”, $output, $ret);
if ($ret > 0) {
echo ‘Failed while downloading files.’;
exit;
}
} //get file
if ( file_exists(“update.ver”) )
unlink(“update.ver”);
if ( file_exists(“list.txt”) )
unlink(“list.txt”);
echo ‘Updated successfully.’;
?>
修改主要为了提高镜像速度,原脚本通过wget来检查每个文件是否有更新,如果有更新下载更新,但是对于100多个文件来说,时间就比较长了。
修改后的脚本会根据版本号和文件大小来确定是否需要下载文件,当然update.ver每次都检查是否有更新。