#!/usr/bin/perl
use IO:)Socket;
require LWP:)UserAgent;
use Time:)localtime;
$ua = new LWP:)UserAgent;
$port = 8080;
$maxconn = SOMAXCONN;
$ip = 0;
print "Server Baslatiliyor.\n";
sleep(5);
my $cmd='ipconfig';
my @routes=`$cmd`;
print "Makina IP Adresi Okundu.\n";
foreach my $route (@routes) {
chomp($route);
if ($route =~ /IP/is){
$ip = $1 if $route =~ /(d+.d+.d+.d+)/;
$lookup = new HTTP:)Request 'GET', "http://www.duzgun.com/cgi-bin/webtools/nslookup.pl?".$ip.":".$port;
$response = $ua->request($lookup);
#$response->content = OK
}
}
if ($ip == 0 ) {
print "Internete ulasilamiyor, Programi sadece (Local Area) da kullanabilirsiniz.\n";
}else{
print "Tebrikler... Servis Kullanima Acilmistir.\n";
}
$server = IO:)Socket:)INET->new(Proto=>"tcp", LocalPort=>$port, Listen=>$maxconn, Reuse=>1) or die "Can't setup server \n";
print "Server inited\nPort: $port\nMaxconnections: $maxconn\nIP Address: $ip\n\n";
binmode(STDOUT);
while ($client = $server->accept) {
$client->autoflush(1);
@header = split(' ', <$client>);
$url = $header[1];
$httpver = $header[2];
if ($header[0] eq "GET" && ($httpver eq "HTTP/1.0" || $httpver eq "HTTP/1.1")) {
if (rindex($url, "/")){
$url =~ s/^///;
$url =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if($url !~ m~^http?~gi) {
$url ='http://'.$domain;
}
$lookup = new HTTP:)Request 'GET', "$url";
$response = $ua->request($lookup);
print $client "$httpver 200 OK\n\n";
print $client $response->content;
print "[", $client->peerhost, "] ", ctime, " send \"$url\"\n";
} else {
print $client "$httpver 404 File Not Found\n\n";
print $client "<HEAD><TITLE>404 File Not Found</TITLE></HEAD>\n";
print $client "<BODY><H1>File Not Found</H1>\n";
print $client "The requested URL $url was not found on this server.\n";
print $client "</BODY>";
print "[", $client->peerhost, "] ", ctime, " failed \"$url\"\n";
}
}
close $client;
}
close $server;