I wrote the following to help deal with browsers complaining about refused connections.
#!/usr/local/bin/perl -w
# simple HTTP server. Responds blindly with a 1x1 transparent PNG. Use with a hosts file for ad blocking
use IO::Socket;
use Net::hostent;
$server = IO::Socket::INET->new(
Proto => 'tcp',
LocalPort => 80,
Listen => SOMAXCONN,
Reuse => 1
) ;
print "*** fakehttp - listening on port 80\n";
while ($client = $server->accept()) {
$client->autoflush(1);
print "Recived a request, responding with 1x1 transparent png...\n";
print $client "HTTP/1.1 200 OK\nContent-Length: 68\n".
"Content-Type: image/x-png\n\n\211\120\116\107\015\012".
"\032\012\000\000\000\015\111\110\104\122\000\000\000".
"\001\000\000\000\001\010\006\000\000\000\037\025\304".
"\211\000\000\000\013\111\104\101\124\170\001\143\140".
"\000\002\000\000\005\000\001\116\013\250\146\000\000".
"\000\000\111\105\116\104\256\102\140\202";
close $client;
}