in reply to socket problem

Well this is much simpler but this works:
#!/usr/bin/perl use IO::Socket; my ($line, $port, $sock, @servers); my $VERSION='1.0'; ($server = $ARGV[0]) || &usage; $begin = ($ARGV[1] || 0); for ($port=$begin;$port<=65000;$port++) { $sock = IO::Socket::INET->new(PeerAddr => $server, PeerPort => $port, Proto => 'tcp'); if ($sock) { print "Connected on port $port\n"; } else { # print "$port failed\n"; } } # End for sub usage { print "Usage: portscan hostname [start at port number]\n"; exit(0); }

Replies are listed 'Best First'.
Re: Re: socket problem
by vxp (Pilgrim) on Jan 07, 2003 at 01:04 UTC
    i, however, want my own code to work. and it does just fine if you takeout the "or die" and $sock->timeout()...which i dont understand, and really want to understand.

      When IO::Socket::INET->new() is unable to make the socket connection it returns false instead of a socket object. So you probably don't want to die just because a port is ignoring you. Try  or $sock = '' instead of or die $!,$@

      Further reading of the IO::Socket::INET POD reveals that you can give Timeout => 5, as part of the hash passed to ->new()

      I have tried your scanner, it does work , but the mechanism you use in makeconn to connect , never seems to return any info.


      I can't believe it's not psellchecked