Gossamer Forum
Home : Products : Links 2.0 : Customization :

Resolve IP nr

Quote Reply
Resolve IP nr
Dear Eliot, I have the following script.

#!/usr/local/bin/perl

use Net::hostent;
use Socket;

$ip = $ENV{'REMOTE_ADDR'};
# The variable "$ENV{'REMOTE_ADDR'}" contains the IP address of the person calling the script.
$h = gethost($ip);
$name = $h->name;
$name =~ s/\/D/\//g;
$name =~ s/\/F/\//g;
$name = lc($name);
$name =~ s/[^-_.a-z0-9]+//g;
# We just tried to resolve the IP into a name, in the next line we check if we didn't mange to get a name,
# in which case, we set the $name variable to be the same as the IP.
if ($name eq "") { $name = $ip; }
chomp $name;
$iporig = $ip;
$count= "C:/inetpub/wwwroot/pages/counter.txt"; # path to counter file
$recent = "C:/inetpub/wwwroot/pages/hits.txt"; # path to recent hits file

if ($ip eq "212.238.90.190") { $ip = "<b><a href=http://www.winwin.demon.nl target=_blank><b><font color=blue>\@<font color=lightblue>wiN</b></font></font></a></b>"; }
if ($ip eq "193.132.124.53") { $ip = "<b><A href=http://www.gwawr.co.uk/ target=_blank><b><font color=cadetblue>Gwawr</b></font></a>"; }
if ($ip eq "212.238.76.194") { $ip = "<b><a href=http://www.pschmitz.demon.nl target=_blank>Law Enforcer</a></b>"; }
if ($ip eq "194.222.211.238") { $ip = "<b><a href=http://www.segapod.demon.co.uk target=_blank>Asam_B</a></b>"; }
# A couple of people i know have static IP addresses, ths means my script can recognise them straight
# away and change the $ip variable so that it contains a link to their respective site.

if ($ip eq $iporig) {
# the above line checks that I haven't already changed the $ip variable in the section below, if I haven't
# then we read the users cookies, if the user is an active participant on the webboards, then they'll have a
# cookie set with their name in it
local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
local(%cookies);
foreach(@rawCookies){
($key, $val) = split (/=/,$_);
$cookies{$key} = $val;
}

$who = $cookies{name};
# OK, so if they had a cookie, we now have it in $who, it'll be encoded, so the following line decodes it.
$who =~ s/%(..)/chr(hex($1))/ge; #decode ASCII hexadecimal values into characters
# It's possible that the user could have edited their cookie and put HTML tags in it, as we are going to
# display the cookie value to the screen, this could be potentialy dangerous, so now we replace < & > with
# the relevant HTML symbol.
$who =~ s/</</g;
$who =~ s/>/>/g;
# If $who is not empty (it'd be empty if there was no cookie available), then change the $ip variable to
# contain the cookie value
if ($who ne "") {$ip = $who;}
# This bit is similar to a section above, basically a few lucky devils automatically get their name colored in
# and hyperlinked.
if ($who eq "Dr OwL") {$ip = "<b><a href=http://www.fly.to/eris23 target=hoot><font color=Blue>D</font><font color=blue>r</font><font color=Yellow>.Ow</font><font color=red>L</font></a></b>";}
if ($who eq "Veg") {$ip = "<b><a href=http://pages.nyu.edu/~scs216 target=_blank><font color=9966ff>Veg</font></a></b>";}
if ($who eq "tress") {$ip = "<b><a href=http://tress.virtualave.net target=_blank>tress</a></b>";}
if ($who eq "Lathem") {$ip = "<b><a href=http://lathem.cjb.net/ target=_blank>Lathem</a></b>";}
if ($who eq "win") {$ip = '<b><a href=http://www.winwin.demon.nl target=_blank><font color=blue>@<font color=lightblue>wiN</font></font></font></a></b>'; $name = "www.nsa.gov";}
if ($who eq "lolli") {$ip = '<b><a href=http://home.tampabay.rr.com/twothree target=_blank><font color=8000ff>23</font></font></a></b>';}
if ($who eq "cypress hill") {$ip = "<b><a href=http://www.the-lamer.com target=_blank>cypress hill</a></b>";}
if ($who eq "salsa") {$ip = '<b><a href=http://altern.org/lizz/ target=_blank><font color=cc99ff>salsa</font></a></b>';}
}

# I didnt think it was a good idea to show everyones IP & hostname, so here we chop off the first bit of the
# hostname, ie:
# tide67.microsoft.com would become microsoft.com. If the user didn't have a cookie set, then their IP will
# show anyway. More initiative to get involved ont he webboards i guess : )
$xx = index($name,".");
if ($xx ne "-1") {
$name = substr($name, $xx + 1, 100);
}

$ip = "$ip";
# Now we have the complete string we want to add to the recent visitors list.
$string = "$name [$ip]";

open(COUNT,"+<$count") | | die "Couldn't open file: $count: $! \n";
$hits = <COUNT>;
# So now we have opened the counter file, $hits now contains the amount of hits we have had so far

open(RECENT,"+<$recent") | | die "Couldn't open file: $recent: $! \n";
@recentArray = <RECENT>;
seek RECENT, 0, 0;

# We've now opened and gone to the top of the Recent hits file, so lets print the new user ($string) and
# write back the other 14 we want to keep
print RECENT "$string\n @recentArray[0] @recentArray[1] @recentArray[2] @recentArray[3]";
print RECENT "@recentArray[4] @recentArray[5] @recentArray[6] @recentArray[7] @recentArray[8]";
print RECENT "@recentArray[9] @recentArray[10] @recentArray[11] @recentArray[12]
@recentArray[13]";
truncate RECENT, tell RECENT;
close RECENT;

open(RECENT,"+<$recent") | | die "Couldn't open file: $recent: $! \n";
@recentArray = <RECENT>;
close RECENT;

# here we bump up the hit counter by one and save it.
$hits = $hits + 1;
seek (COUNT,0,0);
@newcount = $hits;
print COUNT @newcount;
close COUNT;

#print("Content-type: text/html\n\n");
# Here we print the output to the browser, because I am using it in an SSI, i commented out the above line.
# If you are not useing SSI, you'd need to remove the comment to re-enable the header.
print("

<html>
<head>
<title>deej</title>
</head>

<body bgcolor=\"#C0C0C0\" text=\"#000000\" link=\"#C00000\" vlink=\"#C00000\" alink=\"#C00000\">

<table width=\"85%\" border=\"0\" cellspacing=0 cellpadding=0>
<tr>
<td nowrap nowrap align=\"left\" valign=\"top\" width=\"100%\" colspan=\"2\"><div align=\"left\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\"><b>Last 15 Visitors</b></font></div>
</td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">1)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[0]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">2)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[1]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">3)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[2]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">4)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[3]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">5)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[4]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">6)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[5]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">7)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[6]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">8)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[7]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">9)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[8]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"1\" color=\"#330099\">10)</font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[9]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">11)</font></b></font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[10]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">12)</font></b></font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[11]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">13)</font></b></font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[12]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">14)</font></b></font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[13]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"4%\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\">15)</font></b></font></td>
<td nowrap align=\"left\" valign=\"top\" width=\"96%\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"1\">@recentArray[14]</font></td>
</tr>
<tr>
<td nowrap align=\"left\" valign=\"top\" width=\"100%\" colspan=\"2\"><div align=\"left\"><font color=\"#330099\"><b><font face=\"Arial, Helvetica, sans-serif\" size=\"1\"><a
href=\"http://stats.info-x.co.uk\" target=\"_blank\">Stats for Today</a></font></b></font></div>
</td>
</tr>
</table>");

print ("
</font>
</body>
</html>


");

The script works fine and shows the last 15 visitors. It looks like this:
1) xxx.xxx.xxx.xx hostname
2) etc...

To see the script working you have to do: http://www.hostname.com/15.pl
and it open a new screen where you see the last 15 visitors.

BUT.... How can I put this into my home.html screen??? I'm using site_html_temples.pl
Any Idea...

Thanx again...
(I've tried the option from http://www.codes-central.com/WebAdverts-Links.shtml but it didn't work, I get an error... The browser asks to open the file or to download nph-build.pl????)




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


[This message has been edited by Hacktor (edited May 10, 2000).]
Quote Reply
Re: Resolve IP nr In reply to
This is an inappropriate question for this Forum. This question should be posted in the Perl/CGI Forum since it is a general question about another non-LINKS script.

Please re-post this Topic in the Perl/CGI Forum.

Thank you.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: Resolve IP nr In reply to
Sorry Eliot, will post it there, no problem.. I hope you will/can help me with this one...

------------------
Quote Reply
Re: Resolve IP nr In reply to
I did post a possible solution in the other Topic. Thanks for re-posting it, since it does not directly relate to LINKS.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.