LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-26-2007, 09:16 AM   #31
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682

He said he has 50 devices to check. 50 units * several minutes is a very long time.

Something like this in bash using your same test would work:
Code:
read foo < /dev/tcp/hpmedia/22 &
[1] 533
jschiwal@hpamd64:~> sleep 5; kill $! && ssh=closed || ssh=open
[1]+  Done                    read foo < /dev/tcp/hpmedia/22
bash: kill: (533) - No such process
jschiwal@hpamd64:~> read foo < /dev/tcp/hpmedia/23 &
[1] 541
jschiwal@hpamd64:~> sleep 5; kill $! && telnet=closed || telnet=open
jschiwal@hpamd64:~> echo $telnet
closed
[1]+  Terminated              read foo < /dev/tcp/hpmedia/23
jschiwal@hpamd64:~> echo $ssh
open
I haven't used the ksh shell, but it probably has a similar job control feature. "$!" is the last background process. I'm using a double negative. If the port is open, killing the last background process fails.

Last edited by jschiwal; 11-26-2007 at 09:18 AM.
 
Old 11-26-2007, 10:51 AM   #32
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Are you observing a stall even while no firewall is blocking the inactive service port ?
 
Old 11-26-2007, 11:18 AM   #33
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
I tested the scipt and it is rather slow internally. It seems as though it is taking a couple of seconds to determine whether or not the device is up or not(timing out). It there anyway to shorten the length of time it takes to access the device and determine whether or not telnet port 23 is open. thanks
 
Old 11-26-2007, 11:58 AM   #34
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
why has no one commented on my awesome perl solution?
 
Old 11-26-2007, 03:26 PM   #35
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
I am willing to try your one liner perl script but will it produce the output that I am looking for?

PHP Code:
cat check.ksh
#!/bin/ksh
exec 2>/dev/null
printf 
" %-20.20s %-8s %-6s\n" host status telnet
for host in $(<list)
do
        
status=down
        telnet
=closed
        
if ping $host 5 >/dev/null 2>&1
        then
                status
=up
                read foo 
< /dev/tcp/$host/23 && telnet=open
        
else
                
telnet="n/a"
        
fi
        printf 
" %-20.20s %-8s %-6s\n" $host $status $telnet
done
$ ./check.ksh
 host                 status   telnet
 127.0.0.1            up       closed
 192.168.1.1          up       open  
 192.168.1.2          up       closed
 192.168.1.3          down     n
/
This is awesome but slow! thanks
 
Old 11-26-2007, 06:40 PM   #36
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You can reduce the ping timeout from 5 seconds to 2 or even 1 second and so improve my script scan performance.

The timeout is the second parameter of the ping command:
Code:
if ping $host 5 >/dev/null 2>&1
There may be a risk of false negative if your WAN is too busy though.
 
Old 11-26-2007, 07:31 PM   #37
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
awesome. All of you rock.
 
Old 11-28-2007, 01:49 AM   #38
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Quote:
Originally Posted by acid_kewpie View Post
why has no one commented on my awesome perl solution?
I did try it and it seems to hang as well. I used it to test port 23 on "hpmedia.jesnet".

It worked OK testing port 22 however.
 
Old 11-28-2007, 07:56 AM   #39
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Telnet connection timeout is too high. You can use telnet command on any host and you'll see that if the host is up, telnet will need at least a minute to respond that the service in unavailable.

telnet google.com is now running maybe for 4 minutes and still hasn't finished

Last edited by Alien_Hominid; 11-28-2007 at 08:02 AM.
 
Old 11-28-2007, 10:07 AM   #40
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
sure, i *think* the use of the telnet client in itself has been disowned now though.
 
Old 11-28-2007, 10:52 AM   #41
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
What I wanted to say is if telnet client checks for so long if port is open, probably all scripts will do smth similar.
 
Old 11-28-2007, 11:33 AM   #42
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, becuase telnet as a client will retry, generally do an exponentially timed backoff between attempts and such. nmap will send one SYN packet, expect one SYNACK back within a few milliseconds
 
Old 11-28-2007, 11:57 AM   #43
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
I promise I wont ask for anymore help but how can I have this script:

PHP Code:
cat check.ksh 
#!/bin/ksh 
exec 2>/dev/null 
printf 
" %-20.20s %-8s %-6s\n" host status telnet 
for host in $(<list) 
do 
        
status=down 
        telnet
=closed 
        
if ping $host 5 >/dev/null 2>&
        then 
                status
=up 
                read foo 
< /dev/tcp/$host/23 && telnet=open 
        
else 
                
telnet="n/a" 
        
fi 
        printf 
" %-20.20s %-8s %-6s\n" $host $status $telnet 
done 
$ ./check.ksh 
 host                 status   telnet 
 127.0.0.1            up       closed 
 192.168.1.1          up       open   
 192.168.1.2          up       closed 
 192.168.1.3          down     n
/
to include the hostname of the device and have two different categories of devices like NAM's and Sniffers. like for example:

PHP Code:
 NAM             status   telnet 
 127.0.0.1       up       closed 
 192.168.1.1     up       open   
 192.168.1.2     up       closed 
 192.168.1.3     down     n
/a  

 Sniffers       status    telnet 
 127.0.0.1       up       closed 
 192.168.1.1     up       open   
 192.168.1.2     up       closed 
 192.168.1.3     down     n
/
help

Last edited by metallica1973; 11-28-2007 at 12:01 PM.
 
Old 11-28-2007, 11:59 AM   #44
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Op mentioned he can't use nmap and I don't know how perl or /dev/tcp/$host/23 peform their checks. Sorry for misinformation then. Based my opinion on that that all need several minutes to respond.
 
Old 11-28-2007, 12:57 PM   #45
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, certainly in perl it only does one attempt, i assume the onus is on the coder to implement a retry mechanism.
 
  


Reply

Tags
nmap, ping, scan, security



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a shell script for scheduled pinging laucian Linux - Newbie 12 11-08-2007 05:48 AM
script for pinging servers steste Linux - Networking 12 11-16-2004 09:38 AM
Help writing a pinging bash script dehuszar Linux - Software 3 06-18-2004 02:03 PM
Network not pinging any more. duffboygrim Linux - Networking 2 03-30-2004 05:05 PM
bash script prob: pinging boxes bdp Programming 9 02-20-2004 01:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration