Perl script question - Help please
I am working on a cgi script which takes in a user's IP address and then bans that address if it is a particular one. However, I want to set it up so it bans all subaddresses like below:
userip = "100.100.100.100"; #from their computer visible for demo purposes
if ($userip eq "100.100.100.x"){
&dosomething;
}
My problem is that $userip could be 100.100.100.1 through 100.100.100.999
I want it to ban all of them. Is there a wildcard feature or pattern matching one that I'm missing in PERL.
Sorry, I'm pretty new to it.
John Pollock posted this at 16:04 — 6th July 1999.
He has: 628 posts
Joined: Mar 1999
I think you can pattern match a range like this:
/[1-999]/
Only trouble is, you may need to split the IP on the dots to get the last number to use it.
There are some more experienced Perl programmers here that should be able to offer more help for you.
----------
Page Resource: http://www.pageresource.com
JavaScript City: http://www.javascriptcity.com
Java Script: A Beginner's Guide
Page Resource
Anonymous posted this at 16:32 — 6th July 1999.
They have: 5,633 posts
Joined: Jan 1970
As John said ... use this:
if ($userip =~ /100.100.100.[1-999]/) {
&dosomething;
}
Cheers,
Polpus
----------
wdresources
http://www.wdresources.com
Anonymous posted this at 18:44 — 6th July 1999.
They have: 5,633 posts
Joined: Jan 1970
almost everything said....
btw, you don't have to scan through all adresses from 0 to 999 since IPs just go up to 255
cu
patrick
Voltec posted this at 01:07 — 7th July 1999.
They have: 220 posts
Joined: May 1999
Tom,
When an idiot was hunting around my site and posting messages using a double-proxy (to hide his actual IP address) I set up the following:
$ip = $ENV{'REMOTE_ADDR'};
if ( $ip =~ "207.171.193.18" ) {
print "Content-type: text/html\n\n";
print "<METAHTTP-EQUIV=\"Refresh\" Content=\"0;URL=http://www.fbi.gov/\">";
}
Note that I used a Meta refresh because I placed an Include to this 'IP check' at the base of my banner display on each of my pages. You can use a direct Location if you are using it in a stand-alone cgi script. This can be easily modified as mentioned above to span a range of subnets... I didn't have to because the idiot only had fixed holes in systems that he was using. I had to add additonal IP's a couple of times because I would e-mail the system admin of each hole that he used and they started closing them... Needless to say, he stopped bugging us... lol
Matt
----------
1-On-1 Free Basketball Game - Wanna Play?
http://basketball-game.com
1-On-1 Free Basketball Game - Wanna Play?
http://basketball-game.com/
Thousands of Players around the World compete weekly!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.