Page 2 of 2

Posted: Thu Apr 17, 2003 8:19 am
by Nik
when i entered in my index.pl use socket i get this:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, nik@mycosmos.gr and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


--------------------------------------------------------------------------------

Apache/2.0.44 (Win32) mod_perl/1.99_08 Perl/v5.8.0 Server at dell Port 80




this is my index.pl script. pls it works ok except the host thing can u correct it pls?

#!perl
use warnings;
use socket;
use DBI;
use DBD::mysqlPP;
use CGI qw(:standard);

print header;
print start_html("Ôáéíßåò DivX by Nik");

$db = DBI->connect("DBI:mysqlPP:database=db_nik;host=localhost") or
$db = DBI->connect("DBI:mysqlPP:database=db_nik;host=nik.wvbuzz.com", "nik", "macgyver", {RaiseError => 1});

@tainies=();
open(IN, "tainies.txt");
while (<IN>) { push (@tainies, $_); }

$xronos = localtime; $i=0;

$ip = $ENV{REMOTE_ADDR};
@numbers = split(/\./, $ip);
$ip_number = pack("C4", @numbers);
($pc) = (gethostbyaddr($ip_number, 2))[0];

$host = $gethostbyaddr($ip, 2);

print "<body background=/pics/anemos.jpg>";
print "<font size=5 color=Yellow>";

print "<center><font size=5 color=Cyan>- Ðáñáããåëßá Ôáéíéþí DivX by Nik! - <br>";
print "<center><font size=4 color=Pink>* ÅëÜ÷éóôç ðáñáããåëßá åßíáé 5 ôáéíßåò ìå êüóôïò 4 euro áíÜ cd *<br>";
print "<center><font size=4 color=Pink>* Ãéá ðáñáããåëßåò Üíù ôùí 10 ôáéíéþí ôï êüóôïò áíÜ cd êáôåâáßíåé óôá 3 euro *<br>";
print "<center><font size=4 color=Pink>* Ãéá ó÷üëéá êáé ðáñáôçñÞóåéò üóïí áöïñÜ ôéò ôáéíßåò ðáñáêáëþ ãñÜøå ìïõ óôï nik0s\@mycosmos.gr *<br><br>";


print "<form action=check.pl method=post>";
print "<table border=1 width=40% align=Center bordercolor=Yellow style=border-style: solid; border-width: 5 background=/pics/blue.jpg>";
print "<tr>";
print "<td align=center> <font size=5 color=LightGreen> Ôßôëïò Ôáéíßáò </td>";
print "<td align=center> <select name=dvd>";
foreach (@tainies) { print "<option> $_ </option>" };
print "</select> </td>";
print "</tr>";

print "<tr><td colspan =2 align=center> <input type=submit name=emfanisi value='Íáß, èÝëù êáé áõôÞí!'> </td></tr>";
print "</table><br><br><br><br>";


print "<table border=1 width=40% align=Center bordercolor=Yellow style=border-style: solid; border-width: 5 background=/pics/blue.jpg>";
print "<tr> <td align=center> <input type=submit name=kataxorisi value='ÈÝëù íá ðáñáããåßëù áõôÝò ôéò ôáéíßåò'> </td></tr>";
print "<tr> <td align=center> <input type=submit name=emfanisi value='ÈÝëù íá äþ ðïéÝò ôáéíßåò Ý÷ù ðáñáããåßëåé'> </td></tr>";
print "<tr> <td align=center> <input type=submit name=diagrafi value='ÈÝëù íá ìåôáâÜëëù ìéá ôñÝ÷ïõóá ðáñáããåëßá'> </td></tr>";
print "</table>";
print "</form><br><br><br><br>";


print "<form action=eggrafi.php method=post>";
print "<input type=submit name=eggrafi value='ÅããñáöÞ ÌÝëïõò'>";
print "</form>";

print "<form action=progs.php method=post>";
print "<input type=submit name=progs value='ÄéÜöïñá Ðáé÷íßäéá êáé ÐñïãñÜììáôá'>";
print "</form>";

print "<form action=logos.php method=post>";
print "<input type=submit name=logos value='ÈáõìÜóéï Ðíåõìáôéêü êáé Øõ÷ùöåëÝò Êåßìåíï!'>";
print "</form><br>";


print "<center><font size=4 color=Cyan>";
@diary = open(IN, "diary.txt");
while (<IN>) { push (@diary, $_); }
$quote=$diary[int(rand(@diary))];

print "<table border=1 width=80% align=Center bordercolor=Yellow style=border-style: solid; border-width: 5 background=/pics/blue.jpg>";
print "<tr>";
print "<td> <center><font size=4 color=Cyan> $quote </td>";
print "</tr>";
print "</table><br>";


print "<center><font color=Orange> $xronos";
print "<center><font color=Pink> $host";

$sql = "UPDATE counter SET visitor=visitor+1";
$db->do($sql);

$st = $db->prepare( q{SELECT visitor FROM counter});
$st->execute();

@visitor = $st->fetchrow_array();

print "<center><font size=5 color=Yellow> $visitor[0]";
print "<center><a href=personal><img src=/pics/cross.gif></a>";

mail ("nik0s\@mycosmos.gr", "Åðßóêåøç ÁôæÝíôáò $host => $visitor[0]", "", "From: 007\@spy.gr");

Posted: Thu Apr 17, 2003 10:33 am
by volka

Code: Select all

use socket;
use CGI qw(:standard);

print	header,
			start_html('test'),
			h1("client's ip"),
     	ol(
     		li($ip = $ENV&#123;REMOTE_ADDR&#125;),
     		li(@numbers = split(/\./, $ip)),
     		li($ip_number = pack("C4", @numbers)),
     		li($host = (gethostbyaddr($ip_number, 2))&#1111;0]),
				),
			end_html;

exit 0;
that's the script I'm using to display the ip.
You should check your script step-by-step not all-at-once.
Cut pieces out of it (maybe replace it by dummy-implementations) and check again until you found the part that produces errors.

Posted: Fri Apr 18, 2003 3:18 am
by Nik
well i tried it and it works ok volka!

but what i want its NOT the ip address of the client NEITHER the name of the clients pc....

i want instead the hostname! i need something like that:

gethostbyaddr($ENV{'REMOTE_ADDR'}, 2);

b) is what are those li and ho things in your code?
is it pure perl code to produce html output to the browser??

c) what if i use only use cgi;

thank you.

Posted: Fri Apr 18, 2003 4:21 am
by volka
the host is identified by the ip and the ip is all you get from your webserver.
pD9E6BA47.dip.t-dialin.net
if you use this with ping it once again will be resolved to 217.230.186.71.

Haven't thought about it before, but
($pc) = (gethostbyaddr($ip_number, 2))[0]
is useless. I guess you want only the part before the first period but gethostbyaddr does not return an array, only a string.
@numbers = split(/\./, $ip);
separated the ip-string. You might use that as well to split the result of gethostbyaddr.

Code: Select all

$ip = $ENV&#123;'REMOTE_ADDR'&#125;;
# $ip is a string like vvv.xxx.yyy.zzz
@numbers = split(/\./, $ip); 
# @numbers now is an array having the elements vvv, xxx, yyyy and zzz as the string has been separated on each .
ol(
li( ....
that's only formatting the output, the work still is done by the original code snippet (from the script you posted).