Vbs Script to detect and ping the following on any PC Gateway, DNS ans some hardcoded IP

Hello,

I need a Vbs Script to detect and ping the following on any PC   Gateway, DNS ans some hardcoded IP
return results  Example:

Ping Gateway at:           192.168.1.1   = OK
Ping Internal DNS at :   192.168.1.10 = OK
Ping Public DNS at:        8.8.8.8          =  OK



One part of the script with have to detect the DNS ans GATEWAY received by DHCP  and the rest i would like to be able to add static IPs as required.

IPv4 only.


thx!
diascmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Here's a batch script that should do the trick.
It will create a csv file in the script's folder with the results.
The script  will check all IP enabled adapters (but it will assume each adapter has only one IP assigned), and tests up to 4 DNS servers; it will use the respective IP as ping source.
You can define up to 4 static IP addresses to ping in the "Static" variable (a space separated list).
@echo off
setlocal enabledelayedexpansion
set Static=8.8.8.8
set OutFile=%~dpn0.csv
set PingCount=2

>"%OutFile%" echo "ComputerName","Description","DHCP","Gateway","DNS1","DNS2","DNS3","DNS4","Static1","Static2","Static3","Static4"
for /f "delims=" %%a in ('wmic.exe nicconfig WHERE "IPEnabled='True'" GET DefaultIPGateway^,Description^,DHCPEnabled^,DNSServerSearchOrder^,IPAddress /format:list ^| find.exe "="') do (
	for /f "tokens=1,2 delims={}=" %%w in ("%%a") do (
		set %%w=%%x
		if /i "%%w"=="IPAddress" (
			call :Process
		)
	)
)
echo Done.
goto :eof

:Process
echo Testing network accessibility for '!Description!':
echo - DHCP: !DHCPEnabled!
set Line="%ComputerName%","%Description%","%DHCPEnabled%"
set IPAddress=%IPAddress:"=%
if defined DefaultIPGateway (
	set DefaultIPGateway=!DefaultIPGateway:"=!
	<NUL set /p=- Default Gateway:
	ping.exe -4 -n %PingCount% -S !IPAddress! !DefaultIPGateway! | find.exe /i "TTL" >NUL
	if errorlevel 1 (set Result=!DefaultIPGateway!=FAIL) else (set Result=!DefaultIPGateway!=OK)
) else (
	set Result=n/a
)
echo  %Result%
set Line=%Line%,"%Result%"
for /l %%i in (1, 1, 4) do (
	set DNS%%i=
	set Static%%i=
)
if defined DNSServerSearchOrder (
	set DNSServerSearchOrder=!DNSServerSearchOrder:"=!
	for /f "tokens=1-4 delims=," %%a in ("!DNSServerSearchOrder!") do (
		set DNS1=%%a
		set DNS2=%%b
		set DNS3=%%c
		set DNS4=%%d
	)
)
for /l %%i in (1, 1, 4) do (
	<NUL set /p=- DNS %%i:
	if defined DNS%%i (
		ping.exe -4 -n %PingCount% -S !IPAddress! !DNS%%i! | find.exe /i "TTL" >NUL
		if errorlevel 1 (set Result=!DNS%%i!=FAIL) else (set Result=!DNS%%i!=OK)
	) else (
		set Result=n/a
	)
	echo  !Result!
	set Line=!Line!,"!Result!"
)
if defined Static (
	for /f "tokens=1-4 delims= " %%a in ("!Static!") do (
		set Static1=%%a
		set Static2=%%b
		set Static3=%%c
		set Static4=%%d
	)
)
for /l %%i in (1, 1, 4) do (
	<NUL set /p=- Static %%i:
	if defined Static%%i (
		ping.exe -4 -n %PingCount% -S !IPAddress! !Static%%i! | find.exe /i "TTL" >NUL
		if errorlevel 1 (set Result=!Static%%i!=FAIL) else (set Result=!Static%%i!=OK)
	) else (
		set Result=n/a
	)
	echo  !Result!
	set Line=!Line!,"!Result!"
)
echo.
>>"%OutFile%" echo %Line%
goto :eof

Open in new window

0
diascmAuthor Commented:
Thx... but i was trying to avoid any file creation...  and batch files to be honest....

But Still i will give it a test later.
0
oBdACommented:
You can just comment out lines 7 and 78, and there won't be a log file anymore; you'll still have the console report. I just put it in because usually someone wants those results in file format.
Me, I'm trying to avoid VBScript; never really liked it, and Powershell is more ahead of VBScript than VBScript ever was of Batch.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

diascmAuthor Commented:
looks like its inverting the result....     .1 and .109 ARE online

Testing network accessibility for 'HP NC7781 Gigabit Server Adapter':
- DHCP: FALSE
- Default Gateway: 192.168.101.1=FAIL
- DNS 1: 192.168.101.9=FAIL
- DNS 2: n/a
- DNS 3: n/a
- DNS 4: n/a
- Static 1: 8.8.8.8=FAIL
- Static 2: n/a
- Static 3: n/a
- Static 4: n/a
0
oBdACommented:
Sorry, tested this on machine with IPv6 completely disabled, which probably isn't the case on yours.
Additionally, the log file will now only be written if the variable OutFile is set.
@echo off
setlocal enabledelayedexpansion
set Static=8.8.8.8
set OutFile=
set PingCount=2

if defined Outfile >"%OutFile%" echo "ComputerName","Description","DHCP","Gateway","DNS1","DNS2","DNS3","DNS4","Static1","Static2","Static3","Static4"
for /f "delims=" %%a in ('wmic.exe nicconfig WHERE "IPEnabled='True'" GET DefaultIPGateway^,Description^,DHCPEnabled^,DNSServerSearchOrder^,IPAddress /format:list ^| find.exe "="') do (
	for /f "tokens=1,2 delims={}=" %%w in ("%%a") do (
		set %%w=%%x
		if /i "%%w"=="IPAddress" (
			call :Process
		)
	)
)
echo Done.
goto :eof

:Process
for %%a in (%IPAddress%) do (
	echo %%~a| findstr.exe /r "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" >NUL
	if not errorlevel 1 set IPv4Address=%%~a
)
echo Testing network accessibility for '!Description!' ^(%IPv4Address%^):
echo - DHCP: !DHCPEnabled!
set Line="%ComputerName%","%Description%","%DHCPEnabled%"
if defined DefaultIPGateway (
	set DefaultIPGateway=!DefaultIPGateway:"=!
	<NUL set /p=- Default Gateway:
	ping.exe -4 -n %PingCount% -S !IPv4Address! !DefaultIPGateway! | find.exe /i "TTL" >NUL
	if errorlevel 1 (set Result=!DefaultIPGateway!=FAIL) else (set Result=!DefaultIPGateway!=OK)
) else (
	set Result=n/a
)
echo  %Result%
set Line=%Line%,"%Result%"
for /l %%i in (1, 1, 4) do (
	set DNS%%i=
	set Static%%i=
)
if defined DNSServerSearchOrder (
	set DNSServerSearchOrder=!DNSServerSearchOrder:"=!
	for /f "tokens=1-4 delims=," %%a in ("!DNSServerSearchOrder!") do (
		set DNS1=%%a
		set DNS2=%%b
		set DNS3=%%c
		set DNS4=%%d
	)
)
for /l %%i in (1, 1, 4) do (
	<NUL set /p=- DNS %%i:
	if defined DNS%%i (
		ping.exe -4 -n %PingCount% -S !IPv4Address! !DNS%%i! | find.exe /i "TTL" >NUL
		if errorlevel 1 (set Result=!DNS%%i!=FAIL) else (set Result=!DNS%%i!=OK)
	) else (
		set Result=n/a
	)
	echo  !Result!
	set Line=!Line!,"!Result!"
)
if defined Static (
	for /f "tokens=1-4 delims= " %%a in ("!Static!") do (
		set Static1=%%a
		set Static2=%%b
		set Static3=%%c
		set Static4=%%d
	)
)
for /l %%i in (1, 1, 4) do (
	<NUL set /p=- Static %%i:
	if defined Static%%i (
		ping.exe -4 -n %PingCount% -S !IPv4Address! !Static%%i! | find.exe /i "TTL" >NUL
		if errorlevel 1 (set Result=!Static%%i!=FAIL) else (set Result=!Static%%i!=OK)
	) else (
		set Result=n/a
	)
	echo  !Result!
	set Line=!Line!,"!Result!"
)
echo.
if defined Outfile >>"%OutFile%" echo %Line%
goto :eof

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
diascmAuthor Commented:
Perfect!!!! THX!!!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.