Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log request to IP address

Status
Not open for further replies.

M626

Programmer
Mar 13, 2002
299
Does anyone know how to write a simple log script that will log the time of when a request is made to a specific ipaddress. The sripts would run on the server of the IP address i want to monitor. I am new to perl so any samples would be of great assistance.
 
Probably, the best you'll be able to do in Perl would be to have Perl run a server. If you already have servers set up (i.e. Apache for HTTP), the server programs should have options to log requests.

Otherwise...
Code:
  use HTTP::Daemon;
  use HTTP::Status;

  my $d = HTTP::Daemon->new || die;
  print "Please contact me at: <URL:", $d->url, ">\n";
  while (my $c = $d->accept) {
      my $ip = $c->peeraddr;

      while (my $r = $c->get_request) {
             open (LOG, ">>log.txt");
             print LOG "[$ip] " . $c->get_request;
             close (LOG);
              $c->send_error(RC_FORBIDDEN)
      }
      $c->close;
      undef($c);
  }

That would run a simple HTTP daemon on port 80, so anytime somebody tries to access it would log the request info with their IP and send a 403 Forbidden error back.

Is this what you were looking for?

-------------
Cuvou.com | The NEW Kirsle.net
 
that does help but i was hoping for request to any ports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top