Create a .bat file to test connectivity

Posted on 2007-07-26
Last Modified: 2009-09-18
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
Question by:http://
    LVL 2

    Accepted Solution

    Something like
    ping > \\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 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.  
    LVL 19

    Author Comment

    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 I need the if statements that check the result and echo yes/no accordingly
    LVL 19

    Author Comment

    @echo off
    PING -n 1 | FIND "IPOFGOOGLE" >new
    IF NOT ERRORLEVEL 1 ( echo DNS Resolution:GOOD ) ELSE (echo Connectivity:BAD!! )
    PING -n 3 | FIND "TTL=" >new
    IF NOT ERRORLEVEL 1 ( echo Connectivity:GOOD ) ELSE (echo Connectivity:BAD!! )
    portqry -n -e 80 | FIND "LISTENING" >new
    IF NOT ERRORLEVEL 1 ( echo Port 80:GOOD ) ELSE (echo Connectivity:BAD!! )

    Assisted Solution

    Use Netcat to establish a connection with 1sec timeout.
    LVL 8

    Assisted Solution

    Are you familiar with nslookup? Its a good tool to help with dns issues.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now