Hey, this is my first time trying to help someone out, but i believe i know the solution to your problem. Instead of using the $sock->print() method, why not try using $sock as a filehandle. Like this:
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);
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.

In reply to Re: banner grabbing by chrono86
in thread banner grabbing by semio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.