hello fellow monks,
i wrote this little script to check for a remote webserver's general information. after using it a few times i noticed that sometimes it caught the sites html and printed it to the screen, which wasn't in my plan. after that i added a bunch of regex to catch the lines i wanted. basically, it's really clunky and i was just wondering you you could open my mind to a much simpler method. i'm just a novice so please forgive my obvious mistakes. thanks.
use IO::Socket;
if ($#ARGV != 0) {
die "usage: perl $0 [hostname]\n";
} else {
$host = $ARGV[0];
}
$socket = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => $host,
PeerPort => 80,) or die $!;
$socket->autoflush(1);
print $socket "HEAD / HTTP/1.0\015\012\015\012";
while (<$socket>) {
if (/^Set-Cookie:/) {print}
if (/^Server:/) {print}
if (/^P3P:/) {print}
if (/^Last-Modified:/) {print}
if (/^ETag:/) {print}
if (/^X-Powered-By:/) {print}
if (/^HTTP/) {print}
if (/^Accept-Ranges:/) {print}
if (/^Date:/) {print}
if (/^Expires:/) {print}
if (/^Cache-control:/) {print}
if (/^Content-Type:/) {print}
if (/^Location:/) {print}
if (/^Content-Location:/) {print}
if (/^X-Pad:/) {print}
if (/^Connection:/) {print}
if (/^MIME-Version:/) {print}
if (/^Pragma:/) {print}
if (/^Vary:/) {print}
if (/^TCN:/) {print}
if (/^Content-Language:/) {print}
if (/^PICS-Label:/) {print}
}
close $socket;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.