its slightly different from your code, but its easier to understand. I am not completely sure why you have to put the print method outside of the while loop, but i'm pretty sure it has to do with the fact that when you use while to read from a filehandle, it does it line by line (line defined as whatever perl dereferences long strings, set by $/ and defaults to \n). If your head reponse wasn't finished before the newline was, then you are keeping the same socket open, then reopening it which is usually a bad thing, either way i'm still an amateur and i'm sure someone probably has a way better explanation.my $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => $proto); my $request; if ($port == 21) { $request = "blah"; } elsif ($port == 22) { $request = "\012\012"; } elsif ($port == 80) { $request = "HEAD / HTTP/1.0\012\012"; } print $sock $request; while (<$sock>) { chomp (my $server = $_); print $server; } close($sock);
In reply to Re: banner grabbing
by chrono86
in thread banner grabbing
by semio
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |