@echo off
color 1f
Title NETWORK DIAGNOSTICS
mode 80,13
cls
echo.
echo This script will test a few things and save the results in a file named
echo "NetworkReport.txt" on your desktop. When the script is done, just send
echo that file to your tech support person and they'll know what to do next!
echo.
pause
echo. > %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo INTERNET PING TEST >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
:::::::::::::::::::::::::
:: INTERNET TEST ::
:::::::::::::::::::::::::
echo.
echo Testing your network connection and generating a report.
echo Please wait...
echo.
set _PingWANworking=0
::try to ping different WAN IP addresses. If all fail, user has no internet access.
set _PingTarget=8.8.8.8
call :WANpingTest
set _PingTarget=4.2.2.2
call :WANpingTest
set _PingTarget=192.0.43.10
call :WANpingTest
::if internet is working, test DNS next. If not, skip testing DNS
If %_PingWANworking% == 0 (
echo FAILED >> %UserProfile%\Desktop\NetworkReport.txt
echo The computer was unable to ping the following public IP addresses: >> %UserProfile%\Desktop\NetworkReport.txt
echo 8.8.8.8, 4.2.2.2, 192.0.43.10 >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer DOES NOT have internet access. >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
goto SkipDNS
) ELSE (
echo PASSED >> %UserProfile%\Desktop\NetworkReport.txt
echo The computer IS able to ping public IP addresses. >> %UserProfile%\Desktop\NetworkReport.txt >> %UserProfile%\Desktop\NetworkReport.txt
echo The computer DOES have internet access. >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
)
::::::::::::::::::::
:: DNS TEST ::
::::::::::::::::::::
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo INTERNET DNS TEST >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo.
echo Testing DNS.
echo Please wait...
echo.
set _DNSworking=0
::try to ping different WAN domains. If all fail, DNS is not working.
set _PingTarget=www.google.com
call :WANpingTestDNS
set _PingTarget=icann.org
call :WANpingTestDNS
set _PingTarget=amazon.com
call :WANpingTestDNS
If %_DNSworking% == 0 (
echo FAILED >> %UserProfile%\Desktop\NetworkReport.txt
echo The computer has internet access but DNS is not working. >> %UserProfile%\Desktop\NetworkReport.txt
echo It was able to ping at least one public IP address, but was not able to ping any of the >> %UserProfile%\Desktop\NetworkReport.txt
echo following domain names by name: >> %UserProfile%\Desktop\NetworkReport.txt
echo www.google.com, icann.org, amazon.com >> %UserProfile%\Desktop\NetworkReport.txt
) ELSE (
echo PASSED >> %UserProfile%\Desktop\NetworkReport.txt
echo DNS is working. The computer is able to ping external sites by name and by IP address. >> %UserProfile%\Desktop\NetworkReport.txt
)
:SkipDNS
::::::::::::::::::::::::
:: GATEWAY TEST ::
::::::::::::::::::::::::
:: Get the gateways into the variables
for /f "tokens=2,3 delims={,}" %%a in ('"WMIC NICConfig where IPEnabled="True" get DefaultIPGateway /value | find "I" "') do (
set _ipv4GW=%%~a
set _ipv6GW=%%~b
)
set _ipv4Working=0
set _ipv6Working=0
set _gatewayworking=0
::Try to ping the IPv4 gateway if enabled
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo IPv4 GATEWAY TEST >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
if [%_ipv4gw%]==[] goto 4disabled
echo The IPv4 default gateway is detected as: %_ipv4GW% >> %UserProfile%\Desktop\NetworkReport.txt
echo Note that if your computer has more than one default gateway, this may not be correct; see ipconfig /all, below >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
ping -n 1 %_ipv4GW% | find "TTL="
if errorlevel 1 (
echo The default gateway %_ipv4GW% could not be reached.
) ELSE (
set _ipv4Working=1)
If %_ipv4Working% == 1 (
echo PASSED >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer IS able to ping the IPv4 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
) ELSE (
echo FAILED >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer is NOT able to ping the IPv4 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
)
echo. >> %UserProfile%\Desktop\NetworkReport.txt
:skipped4
::Try to ping the IPv6 gateway if enabled
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo IPv6 GATEWAY TEST >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
if [%_ipv6gw%]==[] goto 6disabled
echo The IPv6 default gateway is: %_ipv6GW% >> %UserProfile%\Desktop\NetworkReport.txt
echo Note that if your computer has more than one default gateway, this may not be correct; see ipconfig /all, below. >> %UserProfile%\Desktop\NetworkReport.txt
echo %_ipv6GW% >nul | find "fe80::"
If errorlevel 0 (
echo Note that this is a link-local IPv6 address, which means IPv6 may not be configured correctly. >> %UserProfile%\Desktop\NetworkReport.txt
)
echo. >> %UserProfile%\Desktop\NetworkReport.txt
ping -n 1 %_ipv6GW% | find /v "times" | find "time"
if errorlevel 1 (
echo The default gateway %_ipv6GW% could not be reached.
) ELSE (
set _ipv6Working=1)
If %_ipv6Working% == 1 (
echo PASSED >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer IS able to ping the IPv6 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
) ELSE (
echo FAILED >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer is NOT able to ping the IPv6 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
)
echo. >> %UserProfile%\Desktop\NetworkReport.txt
:skipped6
:::::::::::::::::::::::::
:: WIRELESS TEST ::
:::::::::::::::::::::::::
::check for wireless connection
::test if wlan service is running or not, then display wireless SSID info
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo WIRELESS NETWORKING TEST >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
sc query wlansvc | find "RUNNING"
If errorlevel 1 (
echo The wireless service 'wlansvc' is not running. This MAY mean that the computer >> %UserProfile%\Desktop\NetworkReport.txt
echo does not have a wireless card installed, or it may mean that wlansvc is having an issue. >> %UserProfile%\Desktop\NetworkReport.txt
) ELSE (
netsh wlan show interfaces | find " SSID"
IF errorlevel 1 (
echo The wireless service 'wlansvc' is running. >> %UserProfile%\Desktop\NetworkReport.txt
echo This means this computer likely has a working wireless adapter. >> %UserProfile%\Desktop\NetworkReport.txt
echo However the computer is NOT currently connected to a wireless network. >> %UserProfile%\Desktop\NetworkReport.txt
) ELSE (
echo The computer IS currently connected to a wireless network. >> %UserProfile%\Desktop\NetworkReport.txt
netsh wlan show interfaces | find " SSID" >> %UserProfile%\Desktop\NetworkReport.txt
)
)
::APIPA DETECTOR::
ipconfig /all | find "169.254"
if errorlevel 1 goto adapterinfo
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo SELF ASSIGNED IP ADDRESS DETECTED (APIPA) >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo Below please review IPCONFIG /ALL for more information. At least one self assigned IPv4 address was detected. >> %UserProfile%\Desktop\NetworkReport.txt
echo This means that the adapter was not able to receive a DHCP address, most likely due to a physical disconnection. >> %UserProfile%\Desktop\NetworkReport.txt
:::::::::::::::::::::::::
:: ADAPTER INFO ::
:::::::::::::::::::::::::
:adapterinfo
::display enabled, disabled and disconnected adapters
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo NETWORK ADAPTER STATUS CHECK >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo The following network adapters are CONNECTED: (note that some of these may be virtual) >> %UserProfile%\Desktop\NetworkReport.txt
echo ------------------------------------------------------------------------------------- >> %UserProfile%\Desktop\NetworkReport.txt
wmic /append:%UserProfile%\Desktop\NetworkReport.txt path win32_networkadapter where (netconnectionstatus=2 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo The following network adapters are DISABLED: (note that some of these may be virtual) >> %UserProfile%\Desktop\NetworkReport.txt
echo ------------------------------------------------------------------------------------- >> %UserProfile%\Desktop\NetworkReport.txt
wmic /append:%UserProfile%\Desktop\NetworkReport.txt path win32_networkadapter where (netconnectionstatus=0 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo The following network adapters are DISCONNECTED: (note that some of these may be virtual) >> %UserProfile%\Desktop\NetworkReport.txt
echo ----------------------------------------------------------------------------------------- >> %UserProfile%\Desktop\NetworkReport.txt
wmic /append:%UserProfile%\Desktop\NetworkReport.txt path win32_networkadapter where (netconnectionstatus=7 AND PhysicalAdapter='TRUE') get name, macaddress, manufacturer, netconnectionID
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> %UserProfile%\Desktop\NetworkReport.txt
echo Here are the results of IPCONFIG /ALL for further information: >> %UserProfile%\Desktop\NetworkReport.txt
ipconfig /all >> %UserProfile%\Desktop\NetworkReport.txt
cls
echo.
color 2f
echo DIAGNOSTICS COMPLETE!
echo.
echo Look on your desktop for a text file named "NetworkReport.txt"
echo Please send that file to the person that requested it.
echo.
echo If you are unable to email it from this computer, please instead
echo save it onto a flash drive to bring to another computer,
echo and then email the file to your helpdesk contact from there.
echo.
echo Please read the above, then press E to exit.
Choice /c E
If errorlevel 1 exit /b
::that's all, folks
:::::::::::::::::
:: SUBROUTINES ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WANpingTest
Ping -n 1 %_PingTarget% | find /v "times" | find "time"
If %errorlevel% == 0 set _PingWANworking=1
goto :EOF
:WANpingTestDNS
Ping -n 1 %_PingTarget% | find /v "times" | find "time"
If %errorlevel% == 0 set _DNSworking=1
goto :EOF
:4disabled
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer currently has no IPv4 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
echo The network adapter may be disabled or disconnected, IPv4 protocol may be disabled, >> %UserProfile%\Desktop\NetworkReport.txt
echo or the computer may be failing to receive DHCP options. >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
goto skipped4
:6disabled
echo. >> %UserProfile%\Desktop\NetworkReport.txt
echo This computer currently has no IPv6 default gateway. >> %UserProfile%\Desktop\NetworkReport.txt
echo The network adapter may be disabled or disconnected, IPv6 protocol may be disabled, >> %UserProfile%\Desktop\NetworkReport.txt
echo or the computer may be failing to receive DHCP options. >> %UserProfile%\Desktop\NetworkReport.txt
echo. >> %UserProfile%\Desktop\NetworkReport.txt
goto skipped6
Comments