[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4043
  • Last Modified:

Create a .bat file to test connectivity

Dear All
I need to create a .bat file to test connectivity to my servers, I need to test the following on XP clients:

DNS Resolution
Open Ports

I have an idea about how how to check dns resolution and pings. Initiate a in a bat file and search the return for my IP. If found DNS is allright. Initiate another ping to my IP if there is a reply ping is allright. As for open ports I need to check if the client PC can connect to an open port 5222 on my server. Normally I would ask the user to open a command shell and execute: telnet myip 5222 if the connection is refused it means that they can not access my port there might be some other way.

In short I can not tell the user to execute those commands each time. I need to create a batch file to do the checks and return something like.

DNS : Yes
Ping: Yes
Port : Opened

Any guidance or help is welcome
http:// thevpn.guru
http:// thevpn.guru
3 Solutions
Something like
ping google.com > \\UNC_SHARE_USER_CAN_ACCESS\DNS_Ping.txt
telnet myip 5222 > \\UNC_SHARE_USER_CAN_ACCESS\Port.txt

Obviously the ping and DNS test can be combined or can be done separately.  If you get output like google.com resolved to x.x.x.x DNS works.  And if you get 4 responses below than pinging works as well.  Make sure you chose a host that responds to pings though.

You could create some kind of program that gives them that output in C++ pretty easily or there may be a way to create a batch for it.  Personally I'd rather see the actual output myself though and pushing it to a UNC share where I could just check it would be the easiest thing.  
http:// thevpn.guruAuthor Commented:
Thanks for your help so far..but I would rather prefer that the output is printed on screen in the form mentioned in my Question initially..without sending it over the network..or Internet..so I need the if statements that check the result and echo yes/no accordingly
http:// thevpn.guruAuthor Commented:
@echo off
PING www.google.com -n 1 | FIND "IPOFGOOGLE" >new
IF NOT ERRORLEVEL 1 ( echo DNS Resolution:GOOD ) ELSE (echo Connectivity:BAD!! )
PING www.google.com -n 3 | FIND "TTL=" >new
IF NOT ERRORLEVEL 1 ( echo Connectivity:GOOD ) ELSE (echo Connectivity:BAD!! )
portqry -n www.google.com -e 80 | FIND "LISTENING" >new
IF NOT ERRORLEVEL 1 ( echo Port 80:GOOD ) ELSE (echo Connectivity:BAD!! )
Use Netcat to establish a connection with 1sec timeout.
Are you familiar with nslookup? Its a good tool to help with dns issues.

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now