Re: 2&>1 on Solaris Question

Discussion in 'Perl' started by look, Oct 18, 2003.

  1. look

    look Guest

    what version of Solaris are you running? Have you installed Perl from
    the companion CD or did you download it from sunfreeware? The reason
    i ask these questions is it could be your box is without ssh because
    it's running solaris 8 or earlier, and your version of Perl is living
    under /opt/bin not /usr/local/bin?

    hope this helps


    In article <>, PP133
    <> wrote:

    > I created a perl script to go through a range of IP addresses
    > attempting to logon via ssh protocol version 1. The command for this
    > is "ssh -1 <IP_address>". Basically it attempts to connect using and
    > older ssh protocol version. I made the script to store the server
    > reply when trying to connect, then based on the reply it will list
    > those IP addresses that are still listening on protocol version 1. So
    > if we make a connection attempt to 24.24.24.10 (ssh -1 24.24.24.10)
    > and it loads up with the following message:
    >
    > The authenticity of host '24.24.24.10 (24.24.24.10)' can't be
    > established.
    > RSA1 key fingerprint is
    > 04:6d:81:09:bd:b8:2d:d7:c7:9d:44:cc:3c:d1:01:de.
    > Are you sure you want to continue connecting (yes/no)?
    >
    > That means that the IP address is listening on protocol version 1. So
    > I want to keep this IP address in an array of addresses listening for
    > version 1. Now, if the server is not listening on version 1, it'll
    > give a message like this:
    >
    > Protocol major versions differ: 1 vs. 2
    >
    > There is also the possibility that an IP address won't have ssh
    > listening on it, this makes the script sit there and wait for a
    > response. So I made the script to kill the process after 5 seconds,
    > which is usually long enough to get some sort of response from the
    > server.
    >
    > This all worked great on my redhat box, which I was using to code it,
    > but did not work on the solaris box on which it was intended to work
    > on. I'm using the 2&>1 command to get the error to copy to the
    > STDOUT. For some reason, the solaris box doesn't recognize that "The
    > authenticity of host '...." response as either error or output, hence
    > it just times out when I get that response. I'm using the bash shell
    > on both solaris and redhat so I don't know what the problem is.
    >
    > I'll list my code below so as to be thorough.
    >
    >
    > #This script runs ssh -1 on all the ips in the given range. It then
    > #spits out the IP addresses of the servers that return the message
    > #stating that "Protocol major versions differ 1 vs. 2"
    >
    > #Send 3 arguments, the first being the first 3 octets of the IP addy
    > #beginning of the range, the second being the beginning of the range
    > # and the third being the end of the range
    >
    > #For example, to test 24.24.24.2 to 24.24.24.60 call the script
    > #like this: perl sshcheck.pl 24.24.24 10 60
    >
    > #!/usr/bin/perl
    > use warnings;
    > use strict;
    >
    > my @results;
    > my $count=0;
    > my $result_count=0;
    > my @IPS;
    > my @ValidIPS;
    > my $delay = 5; #sleep time in seconds
    > my $PID;
    > my $argnum=scalar @ARGV;
    >
    > die "3 arguments are needed\n" if($argnum!=3);
    > chomp(my $ip = $ARGV[0]);
    > $ip.=".";
    > chomp(my $begin = $ARGV[1]);
    > chomp(my $end = $ARGV[2]);
    >
    > if($begin > $end){
    > my $temp=$begin;
    > $begin=$end;
    > $end=$temp;
    > }
    >
    > for($begin..$end){
    > $IPS[$count]="$ip$_";
    > print "IPS[$count] = $IPS[$count]: Result_count: $result_count\n";
    > $PID=open IN, "ssh -1 $IPS[$count] 2>&1|" or die "Cannot pipe from
    > ssh\n";
    > sleep $delay;
    > kill 2, $PID if (kill 0, $PID);
    > $results[$result_count]=<IN>;
    > close IN;
    > $count++;
    > if (defined($results[$result_count])){
    > if ($results[$result_count] =~ /.*connection .* refused\./i) {
    > print "Connection refused\n";
    > next;
    > }else { $ValidIPS[$result_count++]=$IPS[$count-1];}
    > }else{
    > print "No response\n";
    > next;
    > }
    > }
    >
    > print "\nThe following IPs are using SSH protocol 1\n";
    > for(1..$result_count){
    > if($results[$_-1] =~ /The authenticity.*/){
    > print "$ValidIPS[$_-1]\n";
    > }
    > }
    >
    >
    >
    > I really appreciate any help anyone can provide. Thanks in advance.
     
    look, Oct 18, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. krigare
    Replies:
    0
    Views:
    840
    krigare
    Dec 27, 2003
  2. Stefan
    Replies:
    2
    Views:
    530
    David Rock
    Apr 25, 2004
  3. Holger Joukl
    Replies:
    1
    Views:
    395
    Stefan
    Apr 13, 2004
  4. JNLSeb
    Replies:
    1
    Views:
    270
    Walter Roberson
    Jan 24, 2008
  5. Replies:
    0
    Views:
    399
Loading...

Share This Page