#!/usr/local/bin/perl5.003
#
#  Very simple client program to search for
#  regular expressions on specified Web sites.
#
require 5.002;
use strict;
use Socket;
# Perl 5 technique for declaring local variables.
my( $host, $in_addr, $proto, $port, $addr );
my( $response, $page, $file, $pattern, %urls );
# Set up some URLs and patterns in an array hash
%urls = (
    "www.ssc.com/lj/" => ["WEB.*","perl.*"],
    "sunsite.unc.edu/mdw/"  => ["kernel","patch"],
);
foreach $page (keys %urls) {
    ($host,$file) = split /\//, $page, 2;
    # Form the HTTP server address from the host
    # name and port number
    $in_addr = (gethostbyname($host))[4];
    $port = 80;
    $addr = sockaddr_in( $port, $in_addr );
    $proto = getprotobyname( 'tcp' );
    # Create an Internet protocol socket.
    socket( S, AF_INET, SOCK_STREAM, $proto )
        or die "socket:$!";
    # Connect our socket to the server socket.
    connect( S, $addr )
        or die "connect:$!";
    # For fflush on socket file handle after every
    # write.
    select(S); $| = 1; select(STDOUT);
    # Send get request to server.
    print S "GET /$file HTTP/1.0\n\n";
    print "===$page===\n";
    # Look for patterns in returned HTML.
    while (<S>) {
        foreach $pattern (@{ $urls{ $page }}) {
            print if /$pattern/i;
        }
    }
    close( S );
}
exit;
  
  
  
  
  
  
  
  
  
    Copyright © 1994 - 2018 Linux Journal.  All rights reserved.