test connectivity for tcp application

Sawyer used Ask the Experts™
i have application that use tcp port 666
i want to test the connectivity to that port from remote location from internet

currency i use telnet hostname 666
i want this to be implemented in the code

any suggestions
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Paul MacDonaldDirector, Information Systems

This would be difficult insofar as not all Windows OSes have telnet by default.  If you were to find some way to distribute it, or make it a prerequiste for using your application, you could certainly call it from within your application.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

That would also be blocked by any firewall.  Incoming connections are usually blocked unless you specifically open the port for it.
If you're willing to use NMAP, the following script will get you started...

@echo off
:: requires http://nmap.org/dist/nmap-5.51-setup.exe
if [%2]==[] echo useage: %0 [host] [port]&goto :eof
for /f "skip=6 tokens=1-4" %%a in ('nmap -Pn -p %2 --version-all --reason --open %1') do (
	if [%%a]==[Nmap] goto :eof
	if [%%b]==[open]	(
		::port open
		set port=%%a
		set state=%%b
		set srv=%%c
		echo port %port% is %state% running %srv%
	) else (
		echo failed.

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial