reexp ip handle

alexho

New Member
Reaction score
0
i am trying to convert symbols into regexp *00 would be .5 in an ip address so
127.0.0.*00 would become 127.0.0.1-5 banning range. not sure if this is feasible i have a substr($buffer, 0, 1)=="r" in a buffer that finds a range and carries out range bans for the user ip if he falls into the range he is banned.
Code:
if (stristr($bufferf,"*00")) {

$p=explode(".", $bufferf);
$p=implode(".\\",$p);
$bufferf = str_ireplace("*00", "([0-9]$|[0-9]{2}$|5$)", $p);
}
then i pass it on to a bunch of these

finnaly to
Code:
$ipr is ip global
    if (eregi("$bufferf",$ipr)) {//searches regular expression to match ip.
$rangebanned=true;
    }
//banned lalala
          header("location: $bannedredirect");
this might work but it might be a bit screwy i havent tested it yet... nor did i pay attention to regexps.. i may want to implement a better way to manage this processes so that i dont overkill banning
 

enouwee

Non ex transverso sed deorsum
Reaction score
240
Why don't you use CIDR masks and ip2long()?

PHP:
<?php

function matchCIDR($address, $ip, $mask)
{
        $mask = 0xffffffff << (32 - $mask);
        return ((ip2long($address) & $mask) == (ip2long($ip) & $mask));
}

?>

The following will match any address in the C-class 127.0.0.0-127.0.0.255:
PHP:
matchCIDR($addr_to_test, '127.0.0.0', 24);

EDIT: you already asked exactly the same question a while ago... :rolleyes:
 

alexho

New Member
Reaction score
0
oh.. i forgot this is a little different though looking thru a file i could call this too
matchCIDR($ip, '$loopedip', 24); i guess ill try it out i totally forgot i had asked this before LOL this seems more reliable.
what is mask for 5,10,20,100 or a better question should i use this for every ban?
 

alexho

New Member
Reaction score
0
/25 is 127? ranges for blocking, would it ever be needed to block below 24 CIDR. ill stop asking questions i should try it first :rolleyes:
what i have now:

Code:
		$ipr = $_SERVER['REMOTE_ADDR'];


if(substr($buffer, 0, 1)=="r") {
$bufferf = str_ireplace("r", "", $buffer); 

$p=explode("|", $bufferf);
$ipc=$p[0];
$cidr=$p[1];
$rangebanned=matchCIDR($ipr, $ipc, $cidr); 

//cidrs: 29=8hosts, 28=16hosts, 27=32hosts,26=64hosts, 25=128hosts, 24=256hosts
//http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#Prefix_aggregation

    /*if (eregi("$bufferf",$ipr)) {//searches regular expression to match ip.
$rangebanned=true;
    }*/
}
i would ban with input 'r127.0.0.1|24'

edit! i tried it with r127.0.0.254|24 it works very well thanks
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top