支付宝赞助帐号:service@kuitao8.com 

下载地址

php查看windows的hosts的文件的方法

Created2017-07-22   Views 161    Author 懒人程序
php查看windows的hosts的文件的方法
<?php
$hosts = file('C:/windows/system32/drivers/etc/hosts');
$group = array();
foreach ($hosts as $line)
{
    if (trim($line) == '' || $line{0} == '#') continue;
    $line = preg_split('/\s+/', $line);
    $ip = array_shift($line);
    foreach ($line as $h)
    {
        if (trim($h) == '') continue;
        $g = explode('.', $h, 2);
        $p = $g[0];
        $g = isset($g[1]) ? $g[1] : $g[0];
        $group[$g][$ip][] = array(
            $p, $g, $h, $ip
        );
    }
}
$ul = array('<ul>');
foreach ($group as $name=>$g)
{
    $ul[] = "<li class='bg1'><span>{$name}</span><ul>";
    foreach ($g as $ip=>$hosts)
    {
        $ul[] = "<li class='bg2'><span>{$ip}</span><ul>";
        foreach ($hosts as $h)
        {
            $ul[] = "<li class='bg3'><span>{$h[0]}({$h[2]})</span></li>";
        }
        $ul[] = '</ul></li>';
    }
    $ul[] = '</ul></li>';
}
$ul[] = "<ul>";
$ul = implode('', $ul);
require 'hosts.phtml';
上一篇: php上传头像检测是不是木马
下一篇: php json自动格式化
支持键盘 ← →

邮件订阅

订阅我们的精彩内容