Gossamer Forum
Home : General : Perl Programming :

Remote Host --> NSLOOKUP

Quote Reply
Remote Host --> NSLOOKUP
I am trying to do an automatic lookup of hosts when someone attempts to SPAM my scripts in my site...I have added the following codes:

Code:

my $remote_address = $ENV{'HTTP_REFERER'};
my $check_host = system("nslookup $remote_address");
print "$check_host";


Also, I am using print MAIL "$check_host"; in mail scripts.

The problem is that the domain name and IP addresses do print in the web page, yet the codes print at the top of the screen with 0 printed where the NSLOOKUP results should print. Also, 0 is only sent via email.

I tried using:

Code:

$check_host = $i;


Then nothing printed.

I did search the perldocs in my server and also at http://www.perl.com and http://www.cpan.org to see if there were any Perl modules that I could use rather than using system to run another application.

Any suggestions are welcome.

Thanks in advance.

Regards,

Eliot Lee

Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Okay...found an old Thread that solves my problem:

http://www.gossamer-threads.com/...=25&Old=allposts

Sorry for the inconvenience of reading this Thread.

Regards,

Eliot Lee

Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
If that solution isn't the correct one from you, try switiching from system to backticks:

my $remote_address = $ENV{'HTTP_REFERER'};
my $check_host = `nslookup $remote_address`;
print $check_host;

--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Ah...good to know, Mark...

Although the codes in the other Thread do work pretty well. The host is printed cleanly and also sent via email.

Thanks...forgot about backticks...Ugh! Smile

Regards,

Eliot Lee

Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Ack, but please get rid of those backticks right now. Huge security hole!! Unlike $ENV{REMOTE_ADDR}, $ENV{HTTP_REFERER} is supplied by the browser. I could easily attack your system by typing:

telnet yourhost.com 80
GET /yourcgi.cgi HTTP/1.0
Referer: ;rm -rf /

and then when your cgi is run $ENV{HTTP_REFERER} will equal ';rm -rf /', not something you want to pass to backticks. =)

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
'zactly the reason I personally never use them (and barely ever use system() for that matter) Smile

But...since "YMMV"..... *G*

[edit: Actually, that was pretty stupid of me offering up that suggestion without providing the warning to go with it. My bad. That's why Alex oversees all here. Smile]
--mark

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Never mind - my solution was resolving IPs. Too early to think Wink But how about using the 'gethostbyname' function.


Dan Smile
Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Thanks, Alex for the helpful suggestion...I did go with the Socket method posted in the other Thread I linked, which works fine and I don't believe posses any security threats.

And I rarely use the system call...mainly in password protected and encrypted scripts.

Regards,

Eliot Lee

Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
By the way, for a good way to get information on a host, try:

http://spamcop.net/hosttracker.shtml

and you can see all the details about that host/ip.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Thanks, Alex...looks like a good resource. I really appreciate you taking time to reply to my Threads lately...especially with the pressure to finish the next release of Links SQL...thanks!

Regards,

Eliot Lee

Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Use the following code to convert an IP-adress into something like "domain.com".

Place the following at the top of your script!
use Socket; # USED BY: gethostbyaddr

Place the following where needed:
# SetStats
$ip = $ENV{'REMOTE_ADDR'};
$hostname = scalar(gethostbyaddr(inet_aton($ip), AF_INET));
$hostname = $1 if $hostname =~ /.*\.([^.]*\.[^.]*)/;
$ip_and_hostname = "$ip / $hostname";


$ip_and_hostname will contain: "194.67.29.299 / domain.com". If you want "194.67.29.299 / addr.modem536.domain.com" remove "$hostname = $1 if $hostname =~ /.*\.([^.]*\.[^.]*)/;"


Quote Reply
Re: Remote Host --> NSLOOKUP In reply to
Thanks, chrishintz...I notice the codes you provided in the other Thread I linked and they work just fine. And I did read more about get** Perl functions at http://www.perl.com...cool stuff!

Regards,

Eliot Lee