LinuxQuestions.org
Help answer threads with 0 replies.
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-24-2007, 03:49 AM   #16
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968

ok, already wrote a long reply then my laptop choked...

ok, so i know what that feels like, i'd say that this sort of scripting *should* be easy for you, and whilst you can bluff knowing network security as a profession, in a similar way i have, the nuts and bolts like this are harder to bluff if anyone pays much attention to the little things.

so anyway, maybe perl is a good way to go... you can open a socket with a lot of control in perl, unlike telnet. check the client example here... http://www.perlfect.com/articles/sockets.shtml which you *could* simplify into a single perl command line.

what sort of output are you looking at? how much faster do you need it to be? I would say you'd get a very good speed up if you look at forking the requests to test everything at once, or nearly so. whilst the successful connections will complete quickly any timeout would delay things substantially, and if you have a dozen of them out of maybe 1000 devices, that'll make your script take a LOT longer without any benefit.

what sort of format are you actually looking at? i'd suggest letting a bash script just fork out the same results out of order, and then just sort the output to order the rows nicely.
 
Old 11-24-2007, 04:13 AM   #17
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Code:
perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "domain.com", PeerPort => "23", ) ? "OPEN\n" : "CLOSED\n";'
 
Old 11-24-2007, 10:24 AM   #18
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Assuming ksh (the real one) is installed, which will be the case at least on the Solaris boxes, you can use its native networking functionality:
Code:
$ cat check.ksh
#!/bin/ksh
exec 2>/dev/null
for host in $(<list)
do read foo < /dev/tcp/$host/23 && echo $host open || echo $host closed 
done
$ cat list
127.0.0.1
192.168.1.1
$ ./check.ksh
127.0.0.1 closed
192.168.1.1 open
 
Old 11-24-2007, 12:31 PM   #19
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
acid_kewpie,

What I mean by formatting is just what it looks like when the log file is produced. I would like something like:

PHP Code:
Row 1           Row 2        Row 3       Row

ip address      up
/down      Telnet      on/off 
This way they can clearly see the ip address of the NAM's and Sniffers and whether or not telnet port 23 if on or off.

I hope that clarifies it a little better. I am trying to keep this position and I see that it requires a little shell scripting knowledge and I am trying to wing it to hopefully get the position. thanks

P.S

It is going to be for about 100 devices right now

Last edited by metallica1973; 11-24-2007 at 12:33 PM.
 
Old 11-24-2007, 02:33 PM   #20
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
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/a
 
Old 11-24-2007, 03:41 PM   #21
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
PHP Code:
host in $(<list) 
Does that mean a file called list where I would have my ip addresses?

I know I am an idiot a shell programming. Sorry
 
Old 11-24-2007, 03:44 PM   #22
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
Yes .
 
Old 11-24-2007, 06:12 PM   #23
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
Quote:
Originally Posted by metallica1973 View Post
PHP Code:
host in $(<list) 
Does that mean a file called list where I would have my ip addresses?
I thought that was clear after post #18.
 
Old 11-25-2007, 03:33 AM   #24
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
ah, never knew that syntax. logical step from a command line stdin redirect i guess...
 
Old 11-26-2007, 07:22 AM   #25
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
one more quick questions: (another stupid question)

How can I e-mail the results to my managers from this script?
 
Old 11-26-2007, 07:25 AM   #26
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
just pipe it into mail...

somescript | mail -s subject user@domain.com

assuming that your local mail relay is working.
 
Old 11-26-2007, 07:39 AM   #27
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
Many thanks you!
 
Old 11-26-2007, 08:10 AM   #28
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Just an FYI. In Linux bash " foo < /dev/tcp/$host/22 && ssh=open" works as well. However, if the port is closed, as when I tried "foo < /dev/tcp/$host/23 && telnet=open" it stalls.
I tried it in ksh and it stalled as well.
 
Old 11-26-2007, 09:55 AM   #29
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
How long did you wait? Wait at least for several minutes.
 
Old 11-26-2007, 10:11 AM   #30
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
/dev/tcp/... is supported at least from bash 2.05a but it is a build conditional flag not always enabled depending on the distributions.

If the service is disabled, I do not observe the redirection stalling with ksh. It does stalls if a firewall block the port but not if the host is reachable with the service disabled.
 
  


Reply

Tags
nmap, ping, scan, security


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:48 AM
script for pinging servers steste Linux - Networking 12 11-16-2004 10:38 AM
Help writing a pinging bash script dehuszar Linux - Software 3 06-18-2004 03:03 PM
Network not pinging any more. duffboygrim Linux - Networking 2 03-30-2004 06:05 PM
bash script prob: pinging boxes bdp Programming 9 02-20-2004 02:50 AM


All times are GMT -5. The time now is 01:06 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration