- 自动切换IP地址 ip.bat
- 虚拟WiFi wifi.bat
- 清理maven残留lastupdate文件 cleanMavenLastUpdt.bat
- 清理DS_Store等隐藏文件
- 自动更新hosts文件 hosts.bat
- ngrok.bat
- mongo.bat MongoVUE
- windows其它命令
- Windows Server 2022 Standard使用VirtualBox
自动切换IP地址 ip.bat
@echo off
::全局变量设置———————————————
set /a x=%random%%%(255-3)+2
set net_name=本地连接
set pre_id=192.168.0
::输入选择 网络方式————————————————-
@echo 请选择网络方式:
@echo 1.静态IP
@echo 2.动态IP
@echo 3.只更新DNS
set /p dnet1=请输入数字[1/2]:
if %dnet1%==1 goto Static_Dns
if %dnet1%==2 goto Dynamic
if %dnet1%==3 goto Static_Dns
cls
@echo 输入错误,请重新输入!
:set_Dns
if %dnet2%==1 goto Dns_opendns
if %dnet2%==2 goto Dns_ali
if %dnet2%==3 goto Dns_114
if %dnet2%==4 goto Dns_google
if %dnet2%==5 goto Dns_local
if %dnet2%==6 goto Dns_NeuStar
if %dnet2%==7 goto Dns_faster
if %dnet2%==8 goto Dns_Panda
if %dnet2%==9 goto Dns_Orzdns
cls
@echo 输入错误,请重新输入!
::输入选择 DNS————————————————-
:Static_Dns
@echo ————————————————-
@echo 请选择DNS服务:
@echo 1.opendns
@echo 2.阿里DNS
@echo 3.114DNS
@echo 4.谷歌DNS
@echo 5.本地DNS
@echo 6.NeuStar
@echo 7.最快DNS组合
@echo 8.熊猫看世界PandaDns
@echo 9.网易ORZDNS
set /p dnet2=请输入数字[1/2/3/4/5/6/7/8/9]:
if %dnet1%==3 goto set_Dns
@echo ————————————————-
@echo 正在设置%net_name%固定IP为:%pre_id%.%x%
netsh interface ip set address name=%net_name% source=static addr=%pre_id%.%x% mask=255.255.255.0 gateway=%pre_id%.1 gwmetric=1
goto set_Dns
::动态IP设置————————————————
:Dynamic
echo 正在设置%net_name%为自动获取IP….
netsh interface ip set address name = %net_name% source = dhcp
echo 正在设置自动获取DNS服务器…
netsh interface ip set dns name = %net_name% source = dhcp
goto Restart
::静态IP设置————————————————
:Dns_opendns
@echo 正在设置opendns服务器…
netsh interface ip set dns %net_name% source=static 208.67.222.222 primary validate=no
netsh interface ip add dns %net_name% 208.67.220.220 index=2 validate=no
netsh interface ip add dns %net_name% 8.8.8.8 index=3 validate=no
goto Restart
:Dns_ali
@echo 正在设置阿里DNS服务器…
netsh interface ip set dns %net_name% source=static 223.6.6.6 primary validate=no
netsh interface ip add dns %net_name% 223.5.5.5 index=2 validate=no
goto Restart
:Dns_114
@echo 正在设置114DNS服务器…
netsh interface ip set dns %net_name% source=static 114.114.115.115 primary validate=no
netsh interface ip add dns %net_name% 114.114.114.114 index=2 validate=no
netsh interface ip add dns %net_name% 114.114.114.119 index=3 validate=no
goto Restart
:Dns_google
@echo 正在设置谷歌DNS服务器…
netsh interface ip set dns %net_name% source=static 8.8.8.8 primary validate=no
netsh interface ip add dns %net_name% 8.8.4.4 index=2 validate=no
netsh interface ip add dns %net_name% 114.114.114.119 index=3 validate=no
goto Restart
:Dns_local
@echo 正在设置本地DNS服务器…
netsh interface ip set dns %net_name% source=static 59.51.78.210 primary validate=no
netsh interface ip add dns %net_name% 8.8.8.8 index=2 validate=no
goto Restart
:Dns_NeuStar
@echo 正在设置NeuStar DNS服务器…
netsh interface ip set dns %net_name% source=static 156.154.70.1 primary validate=no
netsh interface ip add dns %net_name% 156.154.70.22 index=2 validate=no
netsh interface ip add dns %net_name% 156.154.70.25 index=3 validate=no
netsh interface ip add dns %net_name% 8.8.8.8 index=4 validate=no
goto Restart
:Dns_faster
@echo 正在设置最快DNS组合服务器…
netsh interface ip set dns %net_name% source=static 59.51.78.210 primary validate=no
netsh interface ip add dns %net_name% 223.6.6.6 index=2 validate=no
netsh interface ip add dns %net_name% 114.114.115.115 index=3 validate=no
netsh interface ip add dns %net_name% 156.154.70.1 index=4 validate=no
netsh interface ip add dns %net_name% 8.8.8.8 index=5 validate=no
goto Restart
:Dns_Panda
@echo 正在设置熊猫DNS服务器…
netsh interface ip set dns %net_name% source=static 182.254.158.191 primary validate=no
netsh interface ip add dns %net_name% 120.27.30.176 index=2 validate=no
goto Restart
:Dns_Orzdns
@echo 正在设置网易ORZDNS服务器…
netsh interface ip set dns %net_name% source=static 106.2.110.4 primary validate=no
netsh interface ip add dns %net_name% 106.2.110.71 index=2 validate=no
goto Restart
::重启网卡————————————————
:Restart
@echo 重启网卡中…
netsh interface set interface %net_name% disabled
netsh interface set interface %net_name% enable
@echo 刷新DNS缓存…
ipconfig/flushdns
pause
虚拟WiFi wifi.bat
1,打开无线网络服务,然后cmd输入下面命令即可创建一个虚拟wifi,可在网络连接里看到:
netsh wlan set hostednetwork mode=allow ssid=china-net-2015 key=gt1236547
2,在网络连接里, 右键单击已连接到Internet的网络连接,选择“属性”→“共享”,
勾上允许其他网络用户通过此计算机的Internet连接来连接(N)”并选择“虚拟WiFi”。
3.继续在命令提示符中输入:
netsh wlan start hostednetwork
,按回车键运行。虚拟WiFi的红叉消失说明成功
4.手机打开wlan搜索,选择china-net-2015这个名,输入gt1236547即可连接上网
error:A LAN connection is already configured with the IP address that is required for automatic IP address
1.netsh int ip reset h:\temp\resetlog.txt
2.netsh winsock reset catalog
3.重启电脑
wifi.bat
SC start Wlansvc
@ping 127.0.0.1 -n 4 >nul
netsh wlan start hostednetwork
pause
清理maven残留lastupdate文件 cleanMavenLastUpdt.bat
@echo off
@echo 清理E:\maven\repository\ *.lastUpdated
cd E:\maven\repository
for /r %%i in (*.lastUpdated) do (
@echo %%i
del %%i
)
@echo 清理完毕…
pause
清理DS_Store等隐藏文件
@echo off
::清理DS_Store开始———————————————将会清理C:\soft循环目录下所有.DS_Store和以.DS_Store结尾的文件
@echo start_clear_DS_Store...
cd C:\soft
for /f "delims=" %%i in ('dir /s /b /ah *.DS_Store ._* *.lastUpdated ^| sort /r') do (
@echo %%i
del %%i /A /F /Q
)
::强制删除隐藏目录
::rmdir C:\Users\admin\.xxx /S /Q
::rmdir C:\Windows\SoftwareDistribution\Download /S /Q
@echo end_clear_DS_Store...
::清理DS_Store结束———————————————
pause
自动更新hosts文件 hosts.bat
@echo off
if defined converted goto :converted
set ConverterPath=%temp%\HostsGeter_CodeConverter.vbs
set ConverterOutput=%temp%\HostsGeter_GBK.bat
echo inputpath="%~0" >%ConverterPath%
echo outputpath="%ConverterOutput%" >>%ConverterPath%
echo set stm2=createobject("ADODB.Stream") >>%ConverterPath%
echo stm2.Charset ="utf-8" >>%ConverterPath%
echo stm2.Open >>%ConverterPath%
echo stm2.LoadFromFile inputpath >>%ConverterPath%
echo readfile = stm2.ReadText >>%ConverterPath%
echo stm2.Close >>%ConverterPath%
echo Set Stm1 =CreateObject("ADODB.Stream") >>%ConverterPath%
echo Stm1.Type = 2 >>%ConverterPath%
echo Stm1.Open >>%ConverterPath%
echo Stm1.Charset ="GBK" >>%ConverterPath%
echo Stm1.Position = Stm1.Size >>%ConverterPath%
echo Stm1.WriteText "set converted=y" ^& vbcrlf >>%ConverterPath%
echo Stm1.WriteText readfile >>%ConverterPath%
echo Stm1.SaveToFile outputpath,2 >>%ConverterPath%
echo Stm1.Close >>%ConverterPath%
%ConverterPath% && %ConverterOutput%
goto :eof
:converted
chcp 936
:: 更改cmd窗口代码页至 936(GBK)
cls
%1 %2
ver|find " 5.">nul &&goto :st
echo 正在进行 UAC 提权...
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :st","","runas",1)(window.close)&goto :eof
:st
cls
@REM HostsGet Version0.4
cd /d %~dp0
set LogFilePath=%temp%\HostsGeter_log.txt
set DLScriptPath=%temp%\downloadhosts.vbs
set DLPath=%windir%\system32\drivers\etc\hosts_downloaded
set BackupDir=%windir%\system32\drivers\etc
set HostsPath=%windir%\system32\drivers\etc\hosts
set LogToFile=^>^>%LogFilePath% 2^>^&1
set EchoAndLog=call :echoandlog
echo. %LogToFile%
echo ==========[%date% %time%]========== %LogToFile%
echo 日志文件:
echo %LogFilePath%
echo.
echo iLocal=LCase("%DLPath%") > %DLScriptPath% ||(
call :error downloadhosts.vbs 文件创建/写入失败.
)
echo iRemote=LCase("https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts") >> %DLScriptPath%
echo Set xPost=createObject("Microsoft.XMLHTTP") 'Set Post = CreateObject("Msxml2.XMLHTTP") >> %DLScriptPath%
echo xPost.Open "GET",iRemote,0 >> %DLScriptPath%
echo xPost.Send() >> %DLScriptPath%
echo set sGet=createObject("ADODB.Stream") >> %DLScriptPath%
echo sGet.Mode=3 >> %DLScriptPath%
echo sGet.Type=1 >> %DLScriptPath%
echo sGet.Open() >> %DLScriptPath%
echo sGet.Write xPost.ResponseBody >> %DLScriptPath%
echo sGet.SaveToFile iLocal,2 >> %DLScriptPath%
%EchoAndLog% 开始从 GitHub 中下载 hosts 文件...
if exist %DLPath% del %DLPath% /s /q %LogToFile%
%DLScriptPath% || call :error hosts 文件下载失败.
del %DLScriptPath% /s /q %LogToFile%
if not exist %DLPath% call :error hosts 文件下载失败.
%EchoAndLog% 下载完成.
echo.
if exist %HostsPath% (
call :backuphosts
) else (
%EchoAndLog% (原 hosts 文件不存在,跳过备份)
)
%EchoAndLog% 正在替换 hosts 文件...
move %DLPath% %HostsPath% %LogToFile% || call :error hosts 文件替换失败.
%EchoAndLog% hosts 文件已替换.
echo.
%EchoAndLog% 正在刷新系统 DNS 缓存...
ipconfig /flushdns %LogToFile% || call :error DNS 缓存刷新失败.
%EchoAndLog% DNS 缓存已刷新.
echo.
%EchoAndLog% 【操作全部完成!】
echo.
echo 按任意键访问 google.com.hk 进行测试,如取消,请直接关闭本窗口
pause >nul
start https://www.google.com.hk
echo 已经帮你访问 google.com.hk 如可以访问则替换成功.
echo.
goto :end
:backuphosts
%EchoAndLog% 正在备份原 hosts 文件...
set "bakfilename=hosts_%date%_%time:~0,8%.bak"
set bakfilename=%bakfilename:/=-%
set bakfilename=%bakfilename:\=-%
set bakfilename=%bakfilename::=-%
set bakfilename=%bakfilename: =_%
copy %HostsPath% %BackupDir%\%bakfilename% %LogToFile% || call :error hosts 文件备份失败.
%EchoAndLog% 原 hosts 文件已备份到 %BackupDir%\%bakfilename%.
echo.
goto :eof
:error
echo ======================
%EchoAndLog% 错误:%*
start %LogFilePath%
echo 已打开日志文件
goto :end
:echoandlog
echo %*
echo %* %LogToFile%
goto :eof
:end
echo 按任意键关闭
pause >nul
exit
ngrok.bat
ngrok.exe -config tunnel.mobi.cfg -subdomain dqwjoi221ihodw_hello 8080
mongo.bat MongoVUE
mongod -port 11111 -dbpath E:\mongodb\data
windows其它命令
:: 查看端口情况
netstat -ano|findstr 3306
:: 添加注册表忽略弹框提醒(必须加")
REG ADD "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\soft\xxx.exe" /t REG_SZ /d RunAsInvoker
:: Web服务输出乱码问题
由于windows系统CMD窗口默认是GBK,可以使用chcp 65001命令临时切换到UTF-8编码即可;
调用cmd执行结果乱码:比如java启动设置了-Dfile.encoding=UTF-8,此时读取流时需要GBK:
Scanner scanner = new Scanner(new InputStreamReader(process.getInputStream(),"GBK"))
Windows Server 2022 Standard使用VirtualBox
不支持Hyper-V但支持VT-x的CPU硬件下使用VirtualBox步骤:
(
1. 运行下面命令检测是否支持Hyper-V:
> Get-WmiObject Win32_Processor | Select-Object Name, Manufacturer, VirtualizationFirmwareEnabled, VMMonitorModeExtensions
返回4个字段:
Name: CPU的名称
Manufacturer: 制造商(通常是Intel或AMD)
VirtualizationFirmwareEnabled: 虚拟化是否在BIOS中启用
True = 已启用
False = 未启用
VMMonitorModeExtensions: CPU是否支持虚拟化扩展
True = CPU支持虚拟化
False = CPU不支持虚拟化
2. 检测CPU是否支持VT-x:
打开https://www.intel.cn/content/www/cn/zh/products/overview.html
输入搜索如: Intel Core 2 Duo T7700,在结果列表中点开包含规格快速参考的页面中查找先进技术选项的是否有英特尔® 虚拟化技术 (VT-x)并且显示是否支持
3. 如果既不支持Hyper-V也不支持VT-x,那么下面步骤忽略因为系统无法使用VirtualBox
)
4.下载VirtualBox
5.禁用Device Guard和Credential Guard:
打开本地组策略编辑器(输入gpedit.msc)
打开计算机配置 > 管理模板 > 系统 > Device Guard
确保启用基于虚拟化的安全性设置为未配置或禁用
重启系统以应用更改
6.BIOS设置启用VT-x:
通常在启动时按F2、Del等键来启用Intel Virtualization Technology或VT-x选项
7.操作系统和Hyper-V冲突需要禁用Hyper-V:
控制面板 > 程序 > 启用或关闭Windows功能 > 取消勾选Hyper-V,Windows Hypervisor Platform,Virtual Machine Platform等选项后重启电脑