1.

Solve : Network connectivity and batch file?

Answer»

Is there a way to test to see if the computer your on can CONNECT to a remote host at a specific host. This has to be done through a batch file.

In cmd i would just do.. telnet 71.206.23.8 80 and it would connect or refuse to connect. All i have to do is take that and have it display a message. If it does connect then. "Connection established" if it does not "Connection refused." It is not always on port 80 though.

I tried running telnet in a batch file, but i don't know how to catch that output and use it later. I tried messing with error levels.

Can someone please help me?Normally this would just be a MATTER of piping the output to the find command, checking for a message, and setting some sort of indicator.

Telnet however SETS up an alternate universe with a child console where redirection and pipes are not recognized.

If all you need to do is test the availability of the remote host, perhaps you could run a ping command ahead of the telnet session.

You'll probably need to expand on this, but it's a start:

Code: [Select]@echo off
for /f %%x in ('ping -n 1 71.206.23.8 ^| find /i "reply from"') do (
if not ERRORLEVEL 1 telnet 71.206.23.8 80
)

while this code is useful, pinging only checks some default port correct? I possibly want to use this to test a mysql port or an FTP port to make sure an outside computer can connect.

RIght now it does nothing if it can;t connect, and if it can, it opens up the telnet. I don't need to open telnet and have a blank window, i just need there to be a message that pops up saying something like "could connect"

Any additional help would be very appreciated

Thanks
ping doesn't actually "check a port". You can use command line port scanner such as scanline or nmap to check for open ports. Otherwise, if you know some programming languages like Python or Perl, you can do socket programming.



Discussion

No Comment Found