hosts管理工具 HTA+JavaScript

####hosts管理工具 HTA javaScript

 

 #####将下面代码保存为 MT_HOSTS.HTA 文件,执行就可以了,如果要配置vpn服务端地址,修改脚本中PhoneNumber一行中xxxx.xxxx.com为自己的VPN地址。也可以给xxx.xxxx.com这个域名在host指向;

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=GB2312">
<title>HOSTS_TOOL</title>
<HTA:APPLICATION
  APPLICATIONNAME="hosts_tool"
  ID="hosts_tool"
  VERSION="1.5"
  BORDER="thin"
  ICON="C:\Windows\system32\nslookup.exe"
  SCROLL="no"
  SINGLEINSTANCE="no"  
  CAPTION="yes" 
  MAXIMIZEBUTTON="no" 
  MINIMIZEBUTTON="yes" 
  SHOWINTASKBAR="yes" 
  SYSMENU="yes"
  WINDOWSTATE="normal"  
  />


<style> 
    body{ 
        
        border: white 0px solid;
        font-size:14px; 
        margin:0px 10px 0px 10px; 
        padding:0px 0px 0px 0px; 
        /*background-color: #dedbdb;*/
        font-family: "trebuchet ms", calibri, helvetica, sans-serif, "Times New Roman";    
        

    }     
    .memu_btn{
        color: black;
        cursor: hand;
        background-color: #98D2F5;
        border: white 0px solid;
        font-weight: bold;
        margin:3px 0px 0px 5px;        
        height:30px;
        
        font-family: "trebuchet ms", calibri, helvetica, sans-serif, "Times New Roman";
        
        /*设置onmouseover事件*/
        onmouseover: expression(onmouseover=function (){
        this.style.backgroundColor='#cccccc';
        });
        
        /*设置onmouseout事件  ffc080*/
        onmouseout: expression(onmouseout=function (){
        this.style.backgroundColor='#98D2F5'});        

    }

    input {    
        height:30px;
        font-size: 12pt;
        font-family: "trebuchet ms", calibri, helvetica, sans-serif, "Times New Roman";
        margin:0px 0px 0px 0px; 
        
        /*设置onmouseover事件*/
        onmouseover: expression(onmouseover=function (){
        this.style.backgroundColor='#98D2F5';
        });    
            
        /*设置onmouseout事件*/
        onmouseout: expression(onmouseout=function (){
        this.style.backgroundColor=''});
    }
    input.text {
        color:blue;
        cursor:hand;
        font-size:12px;
        background-color:white;
        border:gray 2px solid;
        font-weight:bold;                
        
    }    
    select#menu_select
    {
       border                   : 1px solid #98D2F5;
       font-size                : 12pt;
       background-color: #98D2F5;    
       font-family: "trebuchet ms", calibri, helvetica, sans-serif, "Times New Roman";    
       height:30px;        
    }    
    select#pagerow_size
    {
       border                   : 1px solid ;
       font-size                : 12pt;    
       font-family: "trebuchet ms", calibri, helvetica, sans-serif, "Times New Roman";    
       height:30px;                
    
    }
    
    
    .hidden_div {
        width:100%;
        height:100%;
        display:none;
    }
    
    .show_div{
        width:100%;
        height:100%;

    }

    
 
</style>   
  
  
</head>


<script language="javaScript">

    //window.moveTo(0,0);
    var oShell = new ActiveXObject ("Wscript.shell")
    var wn = new ActiveXObject("WScript.Network")
    var fso = new ActiveXObject("scripting.filesystemobject")
    var objSWbemLocator = new ActiveXObject("WbemScripting.SWbemLocator")

    window.resizeTo(screen.width/2,(screen.height-40)/2);

    
    
    
    function reload_div(div_id){
        reset_div_hidden();
        document.getElementById(div_id).className="show_div";
    }
    function reload_hosts(){
        fpath = oShell.ExpandEnvironmentStrings("%SystemRoot%")+"\\System32\\drivers\\etc\\hosts";

        oShell.Run("cmd /c cacls "+fpath+" /E /R "+wn.username,0,true);    
        
        if (!fso.FileExists(fpath)){        
            var ftxt = fso.CreateTextFile(fpath,true);            
        }
        /*
        ForReading    1    以只读方式打开文件。 不能写这个文件。
        ForWriting    2    以写方式打开文件
        ForAppending    8    打开文件并从文件末尾开始写
        */

        var ftxt = fso.OpenTextFile(fpath,1,true);

        var host_value = ftxt.ReadAll();

        host_value.replace(/crlf/g,"###").replace(/crlf/g,"###") 
        ftxt.Close();
        host_txt.value = host_value;
    
    }
    function host_save(value_str){        
        var fpath = oShell.ExpandEnvironmentStrings("%SystemRoot%")+"\\System32\\drivers\\etc\\hosts";
        var ftxt = fso.CreateTextFile(fpath,true)
        ftxt.Writeline(value_str);
        ftxt.Close();
        oShell.run("cmd /c ipconfig /flushdns",0,true);
    }

    function dis_host(value_str){
        value_str=value_str.replace(/\r\n([0-9])/g,"\r\n#$1");
        host_txt.value=value_str;
        host_save(value_str);


    }
    function reset_obj_height(){
        //host_txt.style.display="none";
        
        txthgt=content.scrollHeight-header.scrollHeight-100;
        //alert(txthgt)        
        host_txt.style.height=txthgt+"px";    
            
        computer_info.style.height=txthgt+"px";
        //computer_info.disabled=true;
        //host_txt.style.display="";        
        //header.style.display="";
        
        reload_hosts();
        //computer_info.innerHTML=get_sysinfo();
    }
    function get_sysinfo(){
         
        var service = objSWbemLocator.ConnectServer(".");  
        //CPU信息 
        var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item();  
        var cpuType="CPU型号:"+cpu.Name+"<br>"
        hostName="计算机名:"+cpu.SystemName+"<br>"
        //内存信息 
        //alert("cpuType:"+cpuType+"cpuCount:"+cpuCount+"hostName:"+hostName)
        var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); 
        
        for (var mem=[],i=0;!memory.atEnd();memory.moveNext()){
                 mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed} 
          }
        //系统信息 
        //alert("ccsdfaew")
        var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item(); 
        //alert("70843fsadfa")
        var physicMenCap="物理内存:"+Math.ceil(system.TotalPhysicalMemory/1024/1024/1024)+"GB <br>"
        curUser="用户名:"+system.UserName+"<br>"
        cpuCount=system.NumberOfProcessors 
        
        ////
        var properties = service.ExecQuery("Select * From win32_diskdrive"); 
        var e = new Enumerator (properties); 
        var disk_info="硬盘信息:"
        for (;!e.atEnd();e.moveNext ()) 
        { 
            var p = e.item ();        
            disk_info=disk_info+p.Model+"/"+Math.ceil(p.size/1024/1024/1024) +"GB  | "
        } 
        
        disk_info=disk_info+"<br>"
        
        
        
        var properties = service.ExecQuery("Select * From Win32_BaseBoard"); 
        var e = new Enumerator (properties); 
        var BoardInfo="主板信息:"
        for (;!e.atEnd();e.moveNext ()) 
        { 
            var p = e.item ();        
            BoardInfo=BoardInfo+p.Manufacturer+"<br>"
        }     
        
        var properties = service.ExecQuery("Select * From Win32_NetworkAdapterConfiguration where MACAddress != null and IPEnabled=true"); 
        var e = new Enumerator (properties); 
        var MacInfo="网卡信息:"
        for (;!e.atEnd();e.moveNext ()) 
        { 
            var p = e.item ();            
            var properties_n = service.ExecQuery("Select * From Win32_NetworkAdapter where Index="+p.Index); 
            var e_n = new Enumerator (properties_n); 
            for (;!e_n.atEnd();e_n.moveNext ()) 
            {
                var p_n = e_n.item ();                
                MacInfo=MacInfo+p.IPAddress(0)+"   "+p.MACAddress+"   |   "
            }
            

        } 
        
        return hostName+curUser+BoardInfo+cpuType+physicMenCap+disk_info+MacInfo
    }
    function add_musebtn(){
        var hidename = "c:\\Windows\\HideFile.vbs";        
        rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\CmdPrompt\\Icon","C:\\Windows\\System32\\cmd.exe","REG_SZ");
        rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\CmdPrompt\\command\\","cmd.exe /s /k pushd %V","REG_SZ");
        rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\Background\\shell\\CmdPrompt\\","命令提示符","REG_SZ");        
        if (oShell.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Hidden")){
             rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\","隐藏文件和扩展名","REG_SZ");        
        }           
        else{
            rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\","显示文件和扩展名","REG_SZ");        
        }    
    
        rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\Icon","%windir%\\System32\\SHELL32.dll,130","REG_SZ");
        rn = oShell.RegWrite("HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\Command\\","WScript.exe c:\\Windows\\HideFile.vbs","REG_SZ");        
        var fvbs = fso.CreateTextFile(hidename,true);
        fvbs.WriteLine("Dim oShell");
        fvbs.WriteLine("Set oShell = WScript.CreateObject("+String.fromCharCode(34)+"WScript.Shell"+String.fromCharCode(34)+")");
        fvbs.WriteLine("'sTitle1 = "+String.fromCharCode(34)+"SSH=0"+String.fromCharCode(34));
        fvbs.WriteLine("'sTitle2 = "+String.fromCharCode(34)+"SSH=1"+String.fromCharCode(34));
        fvbs.WriteLine("if oShell.RegRead("+String.fromCharCode(34)+"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Hidden"+String.fromCharCode(34)+") = 1 then");
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\"+String.fromCharCode(34)+","+String.fromCharCode(34)+"显示文件和扩展名"+String.fromCharCode(34)+","+String.fromCharCode(34)+"REG_SZ"+String.fromCharCode(34));
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Hidden"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"2"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"REG_DWORD"+String.fromCharCode(34)); //'不显示隐藏文件和文件夹
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\HideFileExt"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"1"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"REG_DWORD"+String.fromCharCode(34)); //'不显示文件后缀名
        fvbs.WriteLine("'oShell.SendKeys "+String.fromCharCode(34)+"{F5}+{F10}e"+String.fromCharCode(34));
        fvbs.WriteLine("else");
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKEY_CLASSES_ROOT\\Directory\\background\\shell\\HideFile\\"+String.fromCharCode(34)+","+String.fromCharCode(34)+"隐藏文件和扩展名"+String.fromCharCode(34)+","+String.fromCharCode(34)+"REG_SZ"+String.fromCharCode(34));
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\Hidden"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"1"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"REG_DWORD"+String.fromCharCode(34)); //'显示隐藏文件和文件夹
        fvbs.WriteLine("oShell.RegWrite "+String.fromCharCode(34)+"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\\HideFileExt"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"0"+String.fromCharCode(34)+", "+String.fromCharCode(34)+"REG_DWORD"+String.fromCharCode(34)); //'显示文件后缀名
        fvbs.WriteLine("'oShell.SendKeys "+String.fromCharCode(34)+"{F5}+{F10}e"+String.fromCharCode(34));
        fvbs.WriteLine("end if");
        fvbs.WriteLine("Set oShell = Nothing");
        fvbs.WriteLine("WScript.Quit(0)");
        fvbs.Close();
    }
    
    function create_vpn(){
        pbk_dir=oShell.ExpandEnvironmentStrings("%allusersprofile%")+"\\Application Data\\Microsoft\\Network\\Connections\\Pbk"    
        if (! fso.folderExists(pbk_dir)){
            fso.createfolder(pbk_dir)
        }

        pbk_path=pbk_dir+"\\rasphone.pbk"
 
        objFile = fso.CreateTextFile(pbk_path,true)    
        objFile.WriteLine("[VPN]");
        objFile.WriteLine("Encoding=1");
        objFile.WriteLine("Type=2");
        objFile.WriteLine("AutoLogon=0");
        objFile.WriteLine("UseRasCredentials=1");
        objFile.WriteLine("DialParamsUID=15526343");
        objFile.WriteLine("Guid=EE0684B33EC208418BFD034DFAE3D5F1");
        objFile.WriteLine("BaseProtocol=1");
        objFile.WriteLine("VpnStrategy=2");
        objFile.WriteLine("ExcludedProtocols=0");
        objFile.WriteLine("LcpExtensions=1");
        objFile.WriteLine("DataEncryption=256");
        objFile.WriteLine("SwCompression=1");
        objFile.WriteLine("NegotiateMultilinkAlways=0");
        objFile.WriteLine("SkipNwcWarning=0");
        objFile.WriteLine("SkipDownLevelDialog=0");
        objFile.WriteLine("SkipDoubleDialDialog=0");
        objFile.WriteLine("DialMode=1");
        objFile.WriteLine("DialPercent=75");
        objFile.WriteLine("DialSeconds=120");
        objFile.WriteLine("HangUpPercent=10");
        objFile.WriteLine("HangUpSeconds=120");
        objFile.WriteLine("OverridePref=15");
        objFile.WriteLine("RedialAttempts=3");
        objFile.WriteLine("RedialSeconds=60");
        objFile.WriteLine("IdleDisconnectSeconds=0");
        objFile.WriteLine("RedialOnLinkFailure=0");
        objFile.WriteLine("CallbackMode=0");
        objFile.WriteLine("CustomDialDll=");
        objFile.WriteLine("CustomDialFunc=");
        objFile.WriteLine("CustomRasDialDll=");
        objFile.WriteLine("AuthenticateServer=0");
        objFile.WriteLine("ShareMsFilePrint=1");
        objFile.WriteLine("BindMsNetClient=1");
        objFile.WriteLine("SharedPhoneNumbers=0");
        objFile.WriteLine("GlobalDeviceSettings=0");
        objFile.WriteLine("PrerequisiteEntry=");
        objFile.WriteLine("PrerequisitePbk=");
        objFile.WriteLine("PreferredPort=VPN4-0");
        objFile.WriteLine("PreferredDevice=WAN (L2TP)");
        objFile.WriteLine("PreferredBps=0");
        objFile.WriteLine("PreferredHwFlow=1");
        objFile.WriteLine("PreferredProtocol=1");
        objFile.WriteLine("PreferredCompression=1");
        objFile.WriteLine("PreferredSpeaker=1");
        objFile.WriteLine("PreferredMdmProtocol=0");
        objFile.WriteLine("PreviewUserPw=1");
        objFile.WriteLine("PreviewDomain=0");
        objFile.WriteLine("PreviewPhoneNumber=0");
        objFile.WriteLine("ShowDialingProgress=1");
        objFile.WriteLine("ShowMonitorIconInTaskBar=1");
        objFile.WriteLine("CustomAuthKey=-1");
        objFile.WriteLine("AuthRestrictions=608");
        objFile.WriteLine("TypicalAuth=2");
        objFile.WriteLine("IpPrioritizeRemote=1");
        objFile.WriteLine("IpHeaderCompression=0");
        objFile.WriteLine("IpAddress=0.0.0.0");
        objFile.WriteLine("IpDnsAddress=0.0.0.0");
        objFile.WriteLine("IpDns2Address=0.0.0.0");
        objFile.WriteLine("IpWinsAddress=0.0.0.0");
        objFile.WriteLine("IpWins2Address=0.0.0.0");
        objFile.WriteLine("IpAssign=1");
        objFile.WriteLine("IpNameAssign=1");
        objFile.WriteLine("IpFrameSize=1006");
        objFile.WriteLine("IpDnsFlags=0");
        objFile.WriteLine("IpNBTFlags=1");
        objFile.WriteLine("TcpWindowSize=0");
        objFile.WriteLine("UseFlags=0");
        objFile.WriteLine("IpSecFlags=0");
        objFile.WriteLine("IpDnsSuffix=");
        objFile.WriteLine("NETCOMPONENTS=");
        objFile.WriteLine("ms_server=1");
        objFile.WriteLine("ms_msclient=1");
        objFile.WriteLine("ms_psched=1");
        objFile.WriteLine("MEDIA=rastapi");
        objFile.WriteLine("Port=VPN4-0");
        objFile.WriteLine("Device=WAN (L2TP)");
        objFile.WriteLine("DEVICE=vpn");
        objFile.WriteLine("PhoneNumber=xxx.xxxx.com");
        objFile.WriteLine("AreaCode=");
        objFile.WriteLine("CountryCode=1");
        objFile.WriteLine("CountryID=1");
        objFile.WriteLine("UseDialingRules=0");
        objFile.WriteLine("Comment=");
        objFile.WriteLine("LastSelectedPhone=0");
        objFile.WriteLine("PromoteAlternates=0");
        objFile.WriteLine("TryNextAlternateOnFail=1");
        objFile.Close();

    
        oShell.run("cmd /c ncpa.cpl",0,true)
        oShell.run("explorer.exe "+pbk_path,0,true)
    
    }
    function reset_div_hidden(){
        var arr=["mt_hosts","mt_sysinfo"]        
        for (x=0; x<arr.length; x++) {
            document.getElementById(arr[x]).className="hidden_div";
        };        

    
    }
    window.onload=function(){
        reset_obj_height();
        reload_div("mt_hosts")        

    }
</script>    

<body >
    <div style="width:100%;height:100%;">
        <div id="header"  style="width:100%;">
            <div id="navigator" style="width:100%;">
                <div style="float:left;" >
                    <!--
                    <input id="menu_table" class="memu_btn"  type="button" value="模板管理" onclick="">
                    <input id="menu_user" class="memu_btn"  type="button" value="用户管理" onclick="">                   
                    <select id='menu_select' onchange="">
                        <option  value="" class="memu_btn"  >----选择模块菜单----</option>
                        <option  value="22" class="memu_btn"  >----选择模块菜单111----</option>
                    </select>
                    -->
                         
                    
                </div>
                
                <input id="menu_hosts" class="memu_btn"  type="button" value="修改HOSTS" onclick="reload_div('mt_hosts');reload_hosts();">
                <input id="menu_info" class="memu_btn"  type="button" value="查看硬件信息" onclick="reload_div('mt_sysinfo');computer_info.innerHTML=get_sysinfo();">
                <input id="menu_mousebtn" class="memu_btn"  type="button" value="鼠标右键菜单" onclick="add_musebtn();">
                <input id="menu_mousebtn" class="memu_btn"  type="button" value="新建VPN(PPTP)" onclick="create_vpn();">
                <div style="float:right;">
                    <!--
                    <input id='model_user_text'  type='text'  name='model_user_text' size='' value='' onkeyup="">
                    <input id='model_pwd_text'  type='password'  name='model_pwd_text' value='' onkeyup="">
                    <input id='model_user_login' name="model_user_login"  type=button value="登陆" onclick="">
                    <input id='model_user_login_out'  name="model_user_login_out"  type=button value="注销" onclick="">
                    -->
                </div>                   
            </div>        
        </div>
        <DIV id="content" style="width:100%;height:100%;">
            <div id="mt_hosts" class="hidden_div" >
                <div style="width:100%;height:40px;">  
                    <hr size=1 color=silver> 
                    <input id="host_save_btn" type="button" value="保存" onclick="host_save(host_txt.value);">
                    <input id="host_clean_btn" type="button" value="清空HOSTS" onclick="host_txt.value='';host_save(host_txt.value);">
                    <input id="host_clean_btn" type="button" value="禁用所有HOST" onclick="dis_host(host_txt.value);">
                    <input id="host_clean_btn" type="button" value="刷新" onclick="reload_hosts();">
                    <input id="cancel" type="button" value="退出" onclick="window.close();">            
                </div>
                <hr size=1 color=silver> 
                <div style="width:100%;">
                    <textarea  id="host_txt"  style="width:100%;background-color:#eeeeee;font-size:14pt;border:gray 1px solid;"></textarea>    
                </div> 
            </div>
            <div id="mt_sysinfo" class="hidden_div"  >
                <div>
                    <hr size=1 color=silver> 
                    <font style="color:blue;font-size:16pt;"><strong>计算机信息统计</strong></font>
                    <hr size=1 color=silver> 
                </div>

                <div >                    
                    <div id="computer_info" style="width:100%;background-color:#eeeeee;font-size:14pt;border:gray 1px solid;"></div>
                </div>
            </div>
                        
           
        </DIV>
    </div>  

</body>
</html>

            

 

 

 

posted @ 2019-11-14 17:24  些许记忆  阅读(451)  评论(0编辑  收藏  举报