maujogador

Netfix

Feb 12th, 2018
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 8.41 KB | None | 0 0
  1. @echo off
  2.  
  3. setlocal enabledelayedexpansion&set args=%*&set v=v3.0&set log=%userprofile%\desktop\netfix.log
  4.  
  5. cls & echo.
  6.  
  7. echo               __       ___
  8. echo              /\ \__  /'___\ __
  9. echo   ___      __\ \ ,_\/\ \__//\_\   __  _
  10. echo /' _ `\  /'__`\ \ \/\ \ ,__\/\ \ /\ \/'\
  11. echo /\ \/\ \/\  __/\ \ \_\ \ \_/\ \ \\/^>  ^</
  12. echo \ \_\ \_\ \____\\ \__\\ \_\  \ \_\/\_/\_\
  13. echo  \/_/\/_/\/____/ \/__/ \/_/   \/_/\//\/_/
  14.  
  15. echo.
  16. echo Performs actions similiar to the network repair option and more!
  17. echo See: http://support.microsoft.com/kb/289256
  18. echo.
  19.  
  20. echo [Optional Switches]
  21.  
  22. echo /d   - debug mode
  23. echo /r   - detailed reporting
  24. echo /h   - this help screen; no execution.
  25. echo /w   - winsock reset (http://support.microsoft.com/kb/811259) - requires reboot
  26. echo /t   - tcp/ip reset  (http://support.microsoft.com/kb/299357) - requires reboot
  27.  
  28. echo.
  29. echo Note: This script requires elevated privileges to operate properly. (Vista/7)
  30. echo.
  31.  
  32.  
  33. call :getswitch /h
  34.  
  35. if [!s!]==[/h] goto :eof
  36.  
  37. echo ---[NetFix runtime: %date% %time%]--->!log!
  38.  
  39. set p=Releasing IP address
  40.  
  41. if exist %windir%\system32\ipconfig.exe
  42. (
  43.     echo !p! & title !p! & echo ---[!p!]--- >>!log!
  44.     %windir%\system32\ipconfig.exe /release 1>>!log! 2>>&1
  45.  
  46.     call :getswitch /d
  47.  
  48.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  49.     if [%errorlevel%]==[0] echo Successfully released IP...
  50.     if [%errorlevel%]==[1] echo ERROR: Failed to release IP... check netfix.log
  51.     if [%errorlevel%]==[3] echo NOTE: An IP address has not yet been associated with the network endpoint.
  52. )
  53. else
  54. (
  55.     echo ERROR: failed to release ip address - unable to locate %windir%\system32\ipconfig.exe
  56. )
  57.  
  58.  
  59. call :getswitch /d
  60.  
  61. if [!s!]==[/d] pause
  62.  
  63.  
  64. set p=Flushing ARP cache
  65.  
  66. if exist %windir%\system32\netsh.exe
  67. (
  68.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  69.     %windir%\system32\netsh.exe interface ip delete arpcache 1>>!log! 2>>&1
  70.  
  71.     call :getswitch /d
  72.  
  73.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  74.     if [%errorlevel%]==[0] echo Successfully flushed ARP cache...
  75.     if [%errorlevel%]==[1] echo ERROR: Failed to flush ARP cache... check netfix.log
  76. )
  77. else
  78. (
  79.     if exist %windir%\system32\arp.exe
  80.     (
  81.         %windir%\system32\arp.exe -d * 1>>!log! 2>>&1
  82.  
  83.         call :getswitch /d
  84.        
  85.         if [!s!]==[/d] echo errorlevel: %errorlevel%
  86.         if [%errorlevel%]==[0] echo Successfully flushed ARP cache...
  87.         if [%errorlevel%]==[1] (echo ERROR: Failed to flush ARP cache... check netfix.log)
  88.  
  89.     )
  90.     else
  91.     (
  92.         echo ERROR: failed to flush arp cache - unable to locate %windir%\system32\netsh.exe or %windir%\system32\arp.exe
  93.     )
  94. )
  95.  
  96.  
  97. call :getswitch /d
  98.  
  99. if [!s!]==[/d] pause
  100.  
  101.  
  102. set p=Reloading NetBIOS name cache
  103.  
  104. if exist %windir%\system32\nbtstat.exe
  105. (
  106.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  107.     %windir%\system32\nbtstat.exe -R 1>>!log! 2>>&1
  108.  
  109.     call :getswitch /d
  110.  
  111.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  112.     if [%errorlevel%]==[0] echo Successfully reloaded NetBIOS name cache...
  113.     if [%errorlevel%]==[1] echo ERROR: Failed to reload NetBIOS name cache... check netfix.log
  114.  
  115. )
  116. else
  117. (
  118.     echo ERROR: Failed to reload netbios name cache - unable to locate %windir%\system32\nbtstat.exe
  119. )
  120.  
  121.  
  122. call :getswitch /d
  123.  
  124. if [!s!]==[/d] pause
  125.  
  126.  
  127. set p=Sending NetBIOS name update
  128.  
  129. if exist %windir%\system32\nbtstat.exe
  130. (
  131.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  132.     %windir%\system32\nbtstat.exe -RR 1>>!log! 2>>&1
  133.  
  134.     call :getswitch /d
  135.  
  136.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  137.  
  138. )
  139. else
  140. (
  141.     echo ERROR: Failed to send netbios name update - unable to locate %windir%\system32\nbtstat.exe
  142. )
  143.  
  144. call :getswitch /d
  145.  
  146. if [!s!]==[/d] pause
  147.  
  148. set p=Flushing DNS cache
  149.  
  150. if exist %windir%\system32\ipconfig.exe
  151. (
  152.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  153.     %windir%\system32\ipconfig.exe /flushdns >>!log! 2>>&1
  154.  
  155.     call :getswitch /d
  156.  
  157.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  158.  
  159. )
  160. else
  161. (
  162.     echo ERROR: Failed to flush dns cache - unable to locate %windir%\system32\ipconfig.exe
  163. )
  164.  
  165.  
  166. call :getswitch /d
  167.  
  168. if [!s!]==[/d] pause
  169.  
  170. call :getswitch /w
  171.  
  172. if [!s!]==[/w] call :winsock
  173.  
  174.  
  175. call :getswitch /t
  176.  
  177. if [!s!]==[/t]
  178. (
  179.     call :tcpip
  180. )
  181. else
  182. (
  183.     set p=Renewing IP address
  184.  
  185.     if exist %windir%\system32\ipconfig.exe
  186.     (
  187.         echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  188.         %windir%\system32\ipconfig.exe /renew >>!log! 2>>&1
  189.  
  190.         call :getswitch /d
  191.  
  192.         if [!s!]==[/d] echo errorlevel: %errorlevel%
  193.     )
  194.     else
  195.     (
  196.         echo ERROR: Failed to renew IP address - unable to locate %windir%\system32\ipconfig.exe
  197.     )
  198.  
  199.     call :getswitch /d
  200.  
  201.     if [!s!]==[/d] pause
  202.  
  203.     set p=Registering DNS name
  204.  
  205.     if exist %windir%\system32\ipconfig.exe
  206.     (
  207.         echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  208.         %windir%\system32\ipconfig.exe /registerdns >>!log! 2>>&1
  209.  
  210.         call :getswitch /d
  211.  
  212.         if [!s!]==[/d] echo errorlevel: %errorlevel%
  213.     )
  214.     else
  215.     (
  216.         echo ERROR: Failed to register DNS name - unable to locate %windir%\system32\ipconfig.exe)
  217.     )
  218.  
  219.     call :getswitch /r
  220.  
  221.     if [!s!]==[/r]
  222.     (
  223.         if exist %windir%\system32\ipconfig.exe
  224.         (
  225.             echo ---[ip configuration]--- >>!log!
  226.             %windir%\system32\ipconfig.exe /all >>!log! 2>>&1
  227.         )
  228.  
  229.         if exist %windir%\system32\arp.exe
  230.         (
  231.             echo ---[arp table]--- >>!log!
  232.             %windir%\system32\arp.exe -a 1>>!log! 2>>&1
  233.         )
  234.  
  235.         if exist %windir%\system32\ipconfig.exe
  236.         (
  237.             echo ---[dns resolver cache]--- >>!log!
  238.             %windir%\system32\ipconfig.exe /displaydns >>!log! 2>>&1
  239.         )
  240.  
  241.         if exist %windir%\system32\nbtstat.exe
  242.         (
  243.             echo ---[netbios name tables]--- >>!log!
  244.             %windir%\system32\nbtstat.exe -c >>!log! 2>>&1
  245.             %windir%\system32\nbtstat.exe -n >>!log! 2>>&1
  246.             %windir%\system32\nbtstat.exe -r >>!log! 2>>&1
  247.         )
  248.  
  249.         if exist %windir%\system32\netstat.exe
  250.         (
  251.             echo ---[routing table ^& ethernet/protocol stats]--- >>!log!
  252.             %windir%\system32\netstat.exe -r -e -s >>!log! 2>>&1
  253.         )
  254.  
  255.         if exist %windir%\system32\drivers\etc\hosts
  256.         (
  257.             echo ---[hosts file]--- >>!log!
  258.             type %windir%\system32\drivers\etc\hosts >>!log!
  259.         )
  260.  
  261.         if exist %windir%\system32\netstat.exe
  262.         (
  263.             echo. & echo Please wait while I generate a detailed network report...
  264.             echo ---[all network connections ^& processes]--- >>!log!
  265.             %windir%\system32\netstat.exe -a -b -o -f >>!log! 2>>&1
  266.         )
  267.     )
  268. )
  269.  
  270. echo. & echo Network Repair Complete! & echo ---[Finished: %date% %time%]--->>!log!
  271. title NetFix %v% by Giovanni Heward (giovanni@hewardassociates.com) complete
  272.  
  273. goto :eof
  274.  
  275. :getswitch
  276.  
  277. echo !args!|find.exe /i "%1" >nul 2>&1
  278.  
  279. if %errorlevel%==0 set s=%1
  280.  
  281. goto :eof
  282.  
  283. :tcpip
  284.  
  285. set p=Resetting TCP/IP
  286.  
  287. if exist %windir%\system32\netsh.exe
  288. (
  289.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  290.     %windir%\system32\netsh.exe int ip reset %userprofile%\desktop\netreset.log 1>>!log! 2>>&1
  291.  
  292.     call :getswitch /d
  293.  
  294.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  295.  
  296.     if %errorlevel%==0
  297.     (
  298.         echo Successfully reset TCP/IP
  299.         echo Note: This fix requires a system restart... run "shutdown /a" to abort.
  300.         if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
  301.     )
  302.     else
  303.     (
  304.         echo ERROR: Failed to reset tcp/ip... check netfix.log
  305.     )
  306.  
  307. )
  308. else
  309. (
  310.     echo ERROR: Failed to reset tcp/ip - unable to locate %windir%\system32\netsh.exe
  311. )
  312.  
  313. goto :eof
  314.  
  315. :winsock
  316.  
  317. set p=Resetting Winsock
  318.  
  319. if exist %windir%\system32\netsh.exe
  320. (
  321.     echo. & echo !p! & title !p! & echo ---[!p!]--- >>!log!
  322.     %windir%\system32\netsh.exe winsock reset 1>>!log! 2>>&1
  323.  
  324.     call :getswitch /d
  325.  
  326.     if [!s!]==[/d] echo errorlevel: %errorlevel%
  327.  
  328.     if %errorlevel%==0
  329.     (
  330.         echo Successfully reset winsock
  331.         echo Note: This fix requires a system restart... run "shutdown /a" to abort.
  332.         if exist %windir%\system32\shutdown.exe %windir%\system32\shutdown.exe /r
  333.     )
  334.     else
  335.     (
  336.         echo Failed to reset winsock... check netfix.log
  337.     )
  338.  
  339. )
  340. else
  341. (
  342.     echo ERROR: Failed to reset winsock - unable to locate %windir%\system32\netsh.exe
  343. )
  344.  
  345.  
  346. call :getswitch /d
  347.  
  348. if [!s!]==[/d] pause
Advertisement
Add Comment
Please, Sign In to add comment