Operating System - HP-UX
1756757 Members
2531 Online
108852 Solutions
New Discussion юеВ

Re: telnet xx.xx.xx port, how break the connection in script?

 
SOLVED
Go to solution
bullz
Super Advisor

telnet xx.xx.xx port, how break the connection in script?

Hello Guruz,

Very Good evening to allтАж.

I need your help regarding checking the port for destination are working properly.
Ex telnet 10.xx.xx.x 80

The challenge here is I have more than 500 ports which need to be checked for different destination servers.

The below script is not helping as once I do telnet destination_server port, if itтАЩs connected, I am unable to break the connection in shell script.

if telnet 10.188.36.14 80 < /dev/null 2>&1 | grep -i Connected
then
echo its fine
else
echo port 80 is down!
Fi

Could some let me know if any scripts available for this?
12 REPLIES 12
TTr
Honored Contributor

Re: telnet xx.xx.xx port, how break the connection in script?

Rather than using telnet to check open ports, why don't you look into a port scanning tool such as nmap, nessus, languard etc. Some are free others are not.

What exactly are you trying to do?
bullz
Super Advisor

Re: telnet xx.xx.xx port, how break the connection in script?

Hi

There are few destination servers, I need to check for port connectivity.
There are more number of ports which I need to be checked, I can├в t do this manually as more number of ports which I need to check for all.

telnet xx.xx.xx.x portnumber

Trying...
Connected to xx.xx.xx.x.
Escape character is '^]'.
SSH-2.0-Sun_SSH_1.1

Unable to break here in script.

can you please tell me one freeware s/w where I can achieve this?

Note:- just I need check the connectivity for specific port numbers, whether it├в s connecting or not. Nothing else
Pyers Symon
Advisor

Re: telnet xx.xx.xx port, how break the connection in script?

A few lines of perl will do the job better....

cat sock.pl

#!/usr/bin/perl
my ($host,$port);
$host=10.188.36.14 ;
$port=80;
my $sock=IO::Socket::INET->new("$host:$port") or die "" ;


This will return an zero/non-zero exit code !
TTr
Honored Contributor

Re: telnet xx.xx.xx port, how break the connection in script?

nmap can do what you want.

http://nmap.org/

http://nmap.org/book/man-port-scanning-techniques.html

It is available for HP-UX but it has a lot of dependancies http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/nmap-4.76/

You are better off to install it on a windows PC or Linux.
http://nmap.org/download.html
Hakki Aydin Ucar
Honored Contributor
Solution

Re: telnet xx.xx.xx port, how break the connection in script?

use script attached it is very good ,written in Perl. I use it:

Hakki Aydin Ucar
Honored Contributor

Re: telnet xx.xx.xx port, how break the connection in script?

Bullz,

-script is here attached: and you can call it with this wrapper, it is suitable for port scanning also; from port to port :

#!/bin/ksh
# Port Scanner with PERL
#

echo From Port
read prt1
echo To Port
read prt2
echo IP
read ip

# Init Log File step
bullz
Super Advisor

Re: telnet xx.xx.xx port, how break the connection in script?

It├в s time to say wow├в ┬ж! Wonderful perl script from Hakki Aydin.

I got 95% almost what I want is hee hee. Just one thing, there could be several reasons for which are the ports not connecting
ex
connection refused,
connection timed out
not able to connect

is ter any way I can trace this as well? Instead just to know whether connection is there or not.
TTr
Honored Contributor

Re: telnet xx.xx.xx port, how break the connection in script?

The three connection results along with the successful "connected" result might be similar to the first 4 port states in this document.

http://nmap.org/book/man-port-scanning-basics.html
Hakki Aydin Ucar
Honored Contributor

Re: telnet xx.xx.xx port, how break the connection in script?

My script actually says whether or not associated port is Open OR Closed .

wrapper was missing somehow probably my typo , you can use them together at least to get a list for a given range of ports :

#!/bin/ksh
# Port Scanner with PERL
#

echo From Port
read prt1
echo To Port
read prt2
echo IP
read ip

# Init Log File step
>/tmp/port_check.$ip > /dev/null

while [ $prt1 -lt $prt2 ]
do
echo $ip:$prt1 >> /tmp/port_check.$ip
/aydin/chk_rem_port $ip $prt1 >> /tmp/port_check.$ip
wait
prt1=$(($prt1+1))
done