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 12-07-2007, 08:12 AM   #31
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58

I work in a very stick environment and they have refused me before. Is there a way that we can throw in a ^c to cancel the login the telnet session and add that to the script?
 
Old 12-07-2007, 08:37 AM   #32
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
It's pretty horrible, but here goes. There's probably a better way to do this, so feel free to jump in, anyone.

Code:
read foo < /dev/tcp/$SNIFFERS/23 2>/dev/null &
READPID=$!
sleep 2
if ps | awk '{print $1}' | grep $READPID &> /dev/null
    then
    Telnet=open
    kill $READPID
fi
Basically, we're starting the read, waiting 2 seconds, then looking at the ps output to see if the read process is still running. If it is, then we assume telnet's running on the remote side We kill the read process and continue.

There's an obvious problem with this, though. If network congestion gets bad, you may get false positives, as the read may be waiting for the network, rather than waiting with an open telnet connection. It's also slow - it'll take an extra 2 seconds per host, if the host has telnet running.

Use nmap if at all possible.

Dave

Last edited by ilikejam; 12-07-2007 at 08:40 AM. Reason: typo
 
Old 12-07-2007, 02:17 PM   #33
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
I had to add a sleep 10 second for it work on my script. That is ok but is there a way to make this more efficient?
 
Old 12-07-2007, 03:08 PM   #34
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
I retried the script and it was giving false positives. help!
 
Old 12-07-2007, 03:47 PM   #35
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
I don't think you're going to get round this without some software. Could you see if you can install 'Netcat' or 'nmap'? They might be willing to let Netcat on if they don't like the sound of nmap.

Or maybe you could sneak a Netcat binary into your ~/bin directory? It's only 26kB - they'll never notice (Usual disclaimer: If the admin finds out, and beats you to death with a copy of 'The Practice of System and Network Administration (Limoncelli, Hogan 2001)', then we never had this conversation.)

Dave
 
Old 12-07-2007, 08:08 PM   #36
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
@OP, if your project is legit, there's no reason why admin won't install these tools for your usage. After all, it should be approved by your management. if its legit, it may be worth a try doing some Perl/python socket programming.
 
Old 12-08-2007, 12:22 PM   #37
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
I asked another admin and he said that will not let me use nmap or netcat. I will ask my management and see if I can use those utility if it will make my life easier. With that being said I will ask them on Monday. I will get back to you and once again all of you deserve all the credit. Many thanks.
 
Old 12-08-2007, 06:44 PM   #38
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
hopefully management will see the diff between adding authorised tools when you need them and unnecessary paranoia...
Otherwise you might be better of going with eg Perl, which has socket modules as part of the core install. Use a forking soln?
 
Old 12-08-2007, 08:32 PM   #39
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
I well remember that my SysAdmins were very against the development dept using top on SunOS/Solaris in the early 1990's as it was downloaded and compiled and not in the distibution as originally loaded. Six months later after much arguing with management it was accepted as being the standard tool that it has become and all the fuss forgotten. God forbid, the SysAdmins discovered SAR for performance monitoring which was a bit like using a drogue chute to monitor air speed.
Put your case together and present it after doing your homework to explain away any objections from the SysAdmins, who may be working in a timewarped environment from yesterday. It doesn't stop them being good lads, but they often just have a different set of imperitives to those of the developers.
 
Old 12-08-2007, 09:00 PM   #40
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
some environment set policies that will not allow these tools, like nmap/netcat as they are powerful tools, often used for malicious purposes. So that's a valid "reason" for sysadmins/mgmt not wanting to install such tools.
@OP. see here for other alternative. Or you can start learning some socket programming.
 
Old 12-11-2007, 06:52 AM   #41
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
it looks like sleep 15 seconds (though very slow) is producing reliable results or is this script truly not reliable? Any feedback
 
Old 12-11-2007, 08:59 AM   #42
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
If I use perl, will I still have the same issue using that as oppossed to ksh?

PHP Code:
perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "domain.com", PeerPort => "23", ) ? "OPEN\n" : "CLOSED\n";' 
 
Old 12-11-2007, 02:26 PM   #43
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Works for me
 
Old 12-11-2007, 04:57 PM   #44
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,120

Original Poster
Rep: Reputation: 58
Can you give me an example of how I would plug

PHP Code:
perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "domain.com", PeerPort => "23", ) ? "OPEN\n" : "CLOSED\n";' 
into

PHP Code:
#!/bin/ksh
NAMFILE="nam_output"
SNIFFILE="sniffer_output"
OUT="Report"
MAIL_LIST="test_admin@ccc.edu"

$NAMFILE
$SNIFFILE
$OUT

echo       Daily Sniffer and NAMs Scan as of `date` >> $OUT
echo       Script run with a 5 sec timeout >> $OUT

echo >>$OUT
exec 2
>/dev/null
printf 
" %-15.20s %-8s %-6s \n" NAM Status Telnet >> $NAMFILE

echo "=======================================================" >>$NAMFILE
for NAM in $(<namlist)

do
        
Status=down
        Telnet
=closed
        
if ping $NAM 5 >/dev/null 2>&1
        then
                Status
=up
                read foo 
< /dev/tcp/$NAM/23 2>/dev/null && Telnet=open
#               hname="$(nslookup $NAM | tail -4 | head -1 | awk -F'=' '{print $2}'| sed 's/ //g')"
#               Hostname="${hname%%.*}"
                
[[ -"$Hostname" ]] && Hostname="n/a"
                
printf " %-15.20s %-8s %-6s \n" $NAM $Status $Telnet >> $NAMFILE
        
else
                
Telnet="n/a"
                
printf " %-15.20s %-8s %-6s \n" $NAM $Status $Telnet >> $NAMFILE
        fi


done

printf 
" %-8.20s %-15.20s %-8s %-6s \n" SNIFFERS IP_Address Status Telnet >> $SNIFFILE

echo "======================================================" >> $SNIFFILE

for SNIFFERS in $(<snifflist)

do
        
Status=down
        Telnet
=closed
        
if ping $SNIFFERS 5 >/dev/null 2>&1
        then
                Status
=up
                read foo 
< /dev/tcp/$SNIFFERS/23 2>/dev/null &&  Telnet=open
                IP_Addr
="$(nslookup $SNIFFERS | tail -2 |head -1 | awk -F: '{print $2}'| sed 's/ //g')"
                
IP_Address="${IP_Addr%.*}"
                
[[ -"$IP_Address" ]] && IP_Address="n/a"
                
printf " %-15.20s %-15.20s %-8s %-6s \n" $SNIFFERS $IP_Address $Status $Telnet >>$SNIFFILE
        
else
                
IP_Address="$(nslookup $SNIFFERS | tail -2 |head -1 | awk -F: '{print $2}'| sed 's/ //g')"
                
[[ -"$IP_Address" || "$IP_Address" == "SERVFAIL" ]] && IP_Address="n/a"
                
Telnet="n/a"
                
printf " %-15.20s %-15.20s %-8s %-6s \n" $SNIFFERS $IP_Address $Status $Telnet >>$SNIFFILE

        fi

done


cat $NAMFILE $SNIFFILE 
>> $OUT
mailx 
-s"Daily NAM and Sniffer Report" $MAIL_LIST $OUT 
 
Old 12-11-2007, 05:11 PM   #45
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Just replace
Code:
read foo < /dev/tcp/$SNIFFERS/23 2>/dev/null &&  Telnet=open
with
Code:
Telnet=$(perl -e  'use IO::Socket; print new IO::Socket::INET (PeerAddr => "'$SNIFFERS'", PeerPort => "23", ) ? "open\n" : "closed\n";')
Dave
 
  


Reply


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
how to cut an image ? hectorDUQUE Fedora 1 04-28-2007 10:35 PM
Cut from right to left? LocoMojo Programming 26 03-01-2007 06:14 PM
cut question krock923 Programming 1 10-19-2005 05:03 PM
Ok, maybe I'm not cut out for linux... goosegg Linux - Newbie 5 09-01-2003 04:43 PM
cut-problem dahljor Programming 2 07-08-2003 01:58 PM


All times are GMT -5. The time now is 09:36 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