Skip to content

Instantly share code, notes, and snippets.

@viniciusdaniel
Created November 8, 2018 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusdaniel/3f48cfa969608101f20fbc6f9150613e to your computer and use it in GitHub Desktop.
Save viniciusdaniel/3f48cfa969608101f20fbc6f9150613e to your computer and use it in GitHub Desktop.
Small webserver just responding HTTP 200
#!/usr/bin/perl
use strict;
use IO::Socket;
my $server = IO::Socket::INET->new(
LocalPort => 80,
Type => SOCK_STREAM,
Reuse => 1,
Listen => 20
) or die "Can't start socket $@\n";
my $client;
my $message;
while ($client = $server->accept()) {
my $received;
while(<$client>) {
$message = $_;
last if $message =~ /^\s+$/;
$received .= $message;
}
print $client "HTTP/1.1 200 OK\r\n";
print $client "Content-type: text/html\r\n\r\n";
print $client '<!DOCTYPE html><html><head><title>OK</title></head>';
print $client '<body><pre>' . $received . '</pre></body></html>';
print $client "\r\n";
close($client);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment