Advertisement
Guest User

Untitled

a guest
Jun 12th, 2018
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.93 KB | None | 0 0
  1. @echo off
  2. color 1f
  3. Title NETWORK DIAGNOSTICS
  4. mode 80,13
  5. cls
  6. echo.
  7. echo This script will test a few things and save the results in a file named
  8. echo "NetworkReport.txt" on your desktop. When the script is done, just send
  9. echo that file to your tech support person and they'll know what to do next!
  10. echo.
  11. pause
  12.  
  13.                                                                         :::::::::::::::::::::::::
  14.                                                                         ::    INTERNET TEST    ::
  15.                                                                         :::::::::::::::::::::::::
  16.                                                                
  17.  
  18. set _log=%UserProfile%\Desktop\NetworkReport.txt
  19.  
  20. echo.
  21. echo Testing your network connection and generating a report.
  22. echo Please wait...
  23. echo.
  24. set _PingWANworking=0
  25.  
  26. ::try to ping different WAN IP addresses. If all fail, user has no internet access.
  27. set _PingTarget=8.8.8.8
  28. call :WANpingTest
  29.  
  30. set _PingTarget=4.2.2.2
  31. call :WANpingTest
  32.  
  33. set _PingTarget=192.0.43.10
  34. call :WANpingTest
  35.  
  36. ::if internet is working, test DNS next. If not, skip testing DNS
  37. echo. >> %_log%
  38. If %_PingWANworking% == 0 (
  39.     echo --Internet Ping Test: FAILED >> %_log%
  40.     echo   Failed to ping any public IP addresses. >> %_log%
  41.     goto SkipDNS
  42.     ) ELSE (
  43.     echo --Internet Ping Test: PASSED >> %_log%
  44.     echo   Successfully pinged public IP addresses. >> %_log% >> %_log%
  45.     )
  46.  
  47.                                                                         ::::::::::::::::::::
  48.                                                                         ::    DNS TEST    ::
  49.                                                                         ::::::::::::::::::::
  50.                                                                        
  51. echo.
  52. echo Testing DNS.
  53. echo Please wait...
  54. echo.
  55. set _DNSworking=0
  56.  
  57. ::try to ping different WAN domains. If all fail, DNS is not working.
  58. set _PingTarget=www.google.com
  59. call :WANpingTestDNS
  60.  
  61. set _PingTarget=icann.org
  62. call :WANpingTestDNS
  63.  
  64. set _PingTarget=amazon.com
  65. call :WANpingTestDNS
  66.  
  67. echo. >> %_log%
  68. If %_DNSworking% == 0 (
  69.     echo --Internet DNS Test: FAILED >> %_log%
  70.     echo   Could ping public sites by IP address but not by name. >> %_log%
  71.     ) ELSE (
  72.     echo --Internet DNS Test: PASSED >> %_log%
  73.     echo   Able to ping external sites by name and by IP address. >> %_log%
  74.     )
  75.                                                                
  76. :SkipDNS                                                                   
  77.                                                                        
  78.                                                                         ::::::::::::::::::::::::
  79.                                                                         ::    GATEWAY TEST    ::
  80.                                                                         ::::::::::::::::::::::::
  81. :: Get the gateways into the variables
  82. for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do (
  83.     set _ipv4GW=%%~a
  84.     set _ipv6GW=%%~b
  85.     )
  86. set _ipv4Working=0
  87. set _ipv6Working=0
  88. set _gatewayworking=0
  89.  
  90.  
  91. ::Try to ping the IPv4 gateway if enabled
  92. if [%_ipv4gw%]==[] goto 4disabled
  93.  
  94. ping -n 1 %_ipv4GW% | find "TTL="
  95. if errorlevel 1 (
  96.     echo The default gateway %_ipv4GW% could not be reached.
  97.     ) ELSE (
  98.     set _ipv4Working=1)
  99.    
  100. echo. >> %_log%
  101. If %_ipv4Working% == 1 (
  102.     echo --IPv4 Default Gateway Ping Test: PASSED >> %_log%
  103.     echo   Able to ping %_ipv4GW%. >> %_log%
  104.     ) ELSE (
  105.     echo --IPv4 Default Gateway Ping Test: FAILED >> %_log%
  106.     echo   Not able to ping %_ipv4GW%. >> %_log%
  107.     )  
  108. :skipped4
  109.  
  110.  
  111. ::Try to ping the IPv6 gateway if enabled
  112. if [%_ipv6gw%]==[] goto 6disabled
  113.  
  114.  
  115.  
  116. ping -n 1 %_ipv6GW% | find /v "times" | find "time"
  117. if errorlevel 1 (
  118.     echo The default gateway %_ipv6GW% could not be reached.
  119.     ) ELSE (
  120.     set _ipv6Working=1)
  121.    
  122. echo. >> %_log%
  123. If %_ipv6Working% == 1 (
  124.     echo --IPv6 Default Gateway Ping Test: PASSED >> %_log%
  125.     echo   Able to ping %_ipv6GW%. >> %_log%
  126.     ) ELSE (
  127.     echo --IPv6 Default Gateway Ping Test: FAILED >> %_log%
  128.     echo   Not able to ping %_ipv6GW%. >> %_log%
  129.     )  
  130. :skipped6
  131.  
  132.  
  133.                                                                         :::::::::::::::::::::::::
  134.                                                                         ::    WIRELESS TEST    ::
  135.                                                                         :::::::::::::::::::::::::
  136.                                                    
  137. ::check for wireless connection
  138. ::test if wlan service is running or not, then display wireless SSID info
  139. echo. >> %_log%
  140. sc query wlansvc | find "RUNNING"
  141. If errorlevel 1 (
  142.     echo --Wireless test: SKIPPED >> %_log%
  143.     echo   The wireless service 'wlansvc' is not running or is not present. >> %_log%
  144.     ) ELSE (
  145.     netsh wlan show interfaces | find " SSID"
  146.         IF errorlevel 1 (
  147.         echo --Wireless status: DISCONNECTED >> %_log%
  148.         echo   Not currently connected to a wireless network. >> %_log%
  149.         ) ELSE (
  150.         echo --Wireless status: CONNECTED to the network listed below >> %_log%
  151.         netsh wlan show interfaces | find " SSID" >> %_log%
  152.         )
  153.     )
  154.                                                                         ::APIPA DETECTOR::
  155.                                                                        
  156. ipconfig /all | find "169.254"
  157. if errorlevel 1 goto adapterinfo
  158. echo. >> %_log%
  159. echo --Self assigned IP address test: FAILED >> %_log%
  160. echo  Below please review IPCONFIG /ALL for more information. At least one self assigned IPv4 address was detected.  >> %_log%
  161.  
  162.    
  163.                                                                         :::::::::::::::::::::::::
  164.                                                                         ::    ADAPTER INFO     ::
  165.                                                                         :::::::::::::::::::::::::
  166. :adapterinfo
  167. ::display enabled, disabled and disconnected adapters
  168. echo. >> %_log%
  169. echo. >> %_log%
  170.  
  171. echo. >> %_log%
  172. echo --Network adapters that are CONNECTED: (note that some of these may be virtual) >> %_log%
  173. wmic /append:%_log% path win32_networkadapter where (netconnectionstatus=2 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
  174.  
  175. echo. >> %_log%
  176. echo --Network adapters that are DISABLED: (note that some of these may be virtual) >> %_log%
  177. wmic /append:%_log% path win32_networkadapter where (netconnectionstatus=0 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
  178.  
  179. echo. >> %_log%
  180. echo --Network adapters that are DISCONNECTED: (note that some of these may be virtual) >> %_log%
  181. wmic /append:%_log% path win32_networkadapter where (netconnectionstatus=7 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
  182.  
  183. echo. >> %_log%
  184.  
  185. echo --Detailed information: SEE BELOW >> %_log%
  186. echo   IPCONFIG /ALL >> %_log%
  187. ipconfig /all >> %_log%
  188.  
  189. cls
  190. echo.
  191. color 2f
  192. echo DIAGNOSTICS COMPLETE!
  193. echo.
  194. echo Look on your desktop for a text file named "NetworkReport.txt"
  195. echo Please send that file to the person that requested it.
  196. echo.
  197. echo If you are unable to email it from this computer, please instead
  198. echo save it onto a flash drive to bring to another computer,
  199. echo and then email the file to your helpdesk contact from there.
  200. echo.
  201. echo Please read the above, then press E to exit.
  202. Choice /c E
  203. If errorlevel 1 exit /b
  204. ::that's all, folks
  205.  
  206.  
  207.                                                                                     :::::::::::::::::
  208.                                                                                     :: SUBROUTINES ::
  209. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  210.  
  211.  
  212. :WANpingTest
  213. Ping -n 1 %_PingTarget% | find /v "times" | find "time"
  214. If %errorlevel% == 0 set _PingWANworking=1
  215. goto :EOF
  216.  
  217. :WANpingTestDNS
  218. Ping -n 1 %_PingTarget% | find /v "times" | find "time"
  219. If %errorlevel% == 0 set _DNSworking=1
  220. goto :EOF
  221.  
  222. :4disabled
  223. echo. >> %_log%
  224. echo --IPv4 Default Gateway Ping Test: SKIPPED >> %_log%
  225. echo   No IPv4 default gateway is configured.  >> %_log%
  226. goto skipped4
  227.  
  228. :6disabled
  229. echo. >> %_log%
  230. echo --IPv6 Default Gateway Ping Test: SKIPPED >> %_log%
  231. echo   No IPv6 default gateway is configured.  >> %_log%
  232. goto skipped6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement