2016-10-11 37 views
1

我住在一個賓館,我的房東是善意讓我用他的WiFi,但是,我的連接強度不斷從良好的(5酒吧)切換到壞的(2酒吧)。此外,看起來我的瀏覽器每當它達到2條2時就凍結,這真的很奇怪(或者可能是一個怪異的巧合),解凍它的唯一方法是斷開筆記本電腦上的連接並重新連接。如何編寫一個腳本,如果它的軟弱,會重新啓動我的互聯網連接?

我知道這可能不是最好的或永久的修復,但出於好奇,有沒有辦法編寫一個腳本,將自動切換我的連接斷開,如果我的WiFi連接變弱?如果是這樣,我該怎麼做?

如果很重要,我的操作系統是Windows 8.1。

+2

當你沒有表現出任何的研究工作,我不會在這裏的任何代碼... 不過,我會給你[這](http://stackoverflow.com/questions/35664830/storing-wifi - 信號強度作爲變量)和[this](http://stackoverflow.com/questions/23485848/can-i-enable-disable-a-network-connection-from-the-command-line-或者-ms-dos)文章閱讀。 試着從你自己的建立,並回來更具體的問題:) – geisterfurz007

回答

2

我發現了一個不錯的batch script to automatically repair LAN connection在網上,所以,我與你分享,並希望能夠幫助你!

@echo off 
cls & echo. 
echo    __  ___  
echo    /\ \__ /'___\ __ 
echo ___  __\ \ ,_\/\ \__//\_\ __ _ 
echo /' _ `\ /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\ 
echo /\ \/\ \/\ __/\ \ \_\ \ \_/\ \ \\/^> ^</ 
echo \ \_\ \_\ \____\\ \__\\ \_\ \ \_\/\_/\_\ 
echo \/_/\/_/\/____/ \/__/ \/_/ \/_/\//\/_/ 
echo. 
echo NetFix v2.0c by Giovanni Heward ([email protected]) 
echo. 
echo Performs actions similiar to the network repair option and more! 
echo See: http://support.microsoft.com/kb/289256 
echo. 
echo [Optional Switches] 
echo /w - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot 
echo /t - tcp/ip reset (http://support.microsoft.com/kb/299357) - requires reboot 
echo /d - debug mode 
echo. 
echo Note: This script requires elevated privileges to operate properly. 
echo. 
if [%1]==[/?] goto :eof 
for /f %%d in ('date/t') do set d=%%d & for /f %%t in ('time/t') do set t=%%t 
echo ---[NetFix runtime: %d% %t%]--->>%userprofile%\desktop\netfix.log 

set p=Releasing IP address 
if exist %windir%\system32\ipconfig.exe (
echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\ipconfig.exe /release 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 echo Successfully released IP... 
if %errorlevel%==1 echo ERROR: Failed to release IP... check netfix.log 
if %errorlevel%==3 echo NOTE: An IP address has not yet been associated with the network endpoint. 
) else (echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe) 
if [%1]==[/d] pause 

set p=Flushing ARP cache 
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\netsh.exe interface ip delete arpcache 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 echo Successfully flushed ARP cache... 
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log) 
) else (
if exist %windir%\system32\arp.exe (
%windir%\system32\arp.exe -d * 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 echo Successfully flushed ARP cache... 
if %errorlevel%==1 (echo ERROR: Failed to flush ARP cache... check netfix.log) 
) else (echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe)) 
if [%1]==[/d] pause 

set p=Reloading NetBIOS name cache 
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\nbtstat.exe -R 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 echo Successfully reloaded NetBIOS name cache... 
if %errorlevel%==1 (echo ERROR: Failed to reload NetBIOS name cache... check netfix.log) 
) else (
echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe) 
if [%1]==[/d] pause 

set p=Sending NetBIOS name update 
if exist %windir%\system32\nbtstat.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\nbtstat.exe -RR 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
) else (echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe) 
if [%1]==[/d] pause 

set p=Flushing DNS cache 
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\ipconfig.exe /flushdns 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
) else (echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe) 
if [%1]==[/d] pause 

if [%1]==[/w] goto :winsock 
if [%1]==[/t] goto :ipreset 
goto :cont 

:ipreset 
set p=Resetting TCP/IP 
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 (
echo Successfully reset TCP/IP 
echo Note: This fix requires a system restart... run "shutdown /a" to abort. 
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r 
) 
if %errorlevel%==1 (echo ERROR: Failed to reset tcp/ip... check netfix.log) 
) else (echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe) 
goto :end 

:winsock 
set p=Resetting Winsock 
if exist %windir%\system32\netsh.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\netsh.exe winsock reset 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
if %errorlevel%==0 (
echo Successfully reset winsock 
echo Note: This fix requires a system restart... run "shutdown /a" to abort. 
if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r 
) 
if %errorlevel%==1 (echo Failed to reset winsock... check netfix.log) 
) else (echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe) 
if [%1]==[/d] pause 

:cont 
set p=Renewing IP address 
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\ipconfig.exe /renew 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
) else (echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe) 
if [%1]==[/d] pause 

set p=Registering DNS name 
if exist %windir%\system32\ipconfig.exe (
echo. & echo %p% & title %p% & echo ---[%p%]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\ipconfig.exe /registerdns 1>>%userprofile%\desktop\netfix.log 2>>&1 
if [%1]==[/d] echo errorlevel: %errorlevel% 
) else (echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe) 

:end 
if exist %windir%\system32\ipconfig.exe (
echo ---[ip configuration]--- >>%userprofile%\desktop\netfix.log 
%windir%\system32\ipconfig.exe /all >>%userprofile%\desktop\netfix.log 2>>&1 
) 
echo. & echo Network Repair Complete! & echo ---[Finished: %d% %t%]--->>%userprofile%\desktop\netfix.log 
set p= & title NetFix v2.0b by Giovanni Heward ([email protected]) complete! & set t= & set d= 
::********************************************************************************** 
::Added by Hackoo to convert log file to Unicode output on 06/10/2016 
Cmd /U /C Type %userprofile%\desktop\netfix.log > %userprofile%\desktop\netfix.txt 
If exist %userprofile%\desktop\netfix.log Del %userprofile%\desktop\netfix.log 
Start "" %userprofile%\desktop\netfix.txt 
::********************************************************************************** 
pause & exit 
+1

你能請也分享來源? – aschipfl

+1

@aschipfl我編輯我的答案,我添加了鏈接,我發現這個腳本;) – Hackoo

+0

@Hackoo我如何提升我的權限,使腳本正常工作? –

相關問題