Cep Posted May 21, 2007 Share Posted May 21, 2007 Hi, I want to run a quick regex against IP addresses but I want to do it on blocks for example, 65.54.188\.[0-9]{1,3} Should give me all IP addresses for the MSN search bots in the 65.54.188.1 - .255 range correct? Quote Link to comment https://forums.phpfreaks.com/topic/52315-solved-ip-part-match/ Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 try 65\.54\.188\.[0-9]{1,3} more complex 65\.54\.188\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) Quote Link to comment https://forums.phpfreaks.com/topic/52315-solved-ip-part-match/#findComment-258106 Share on other sites More sharing options...
Cep Posted May 21, 2007 Author Share Posted May 21, 2007 The more complex one would be best then as my original would do a range of 65.54.188.1 - 999 and the second will only do up to 255? Quote Link to comment https://forums.phpfreaks.com/topic/52315-solved-ip-part-match/#findComment-258114 Share on other sites More sharing options...
MadTechie Posted May 21, 2007 Share Posted May 21, 2007 correct but i think the simple one is quicker.. the choice is your Quote Link to comment https://forums.phpfreaks.com/topic/52315-solved-ip-part-match/#findComment-258127 Share on other sites More sharing options...
Cep Posted May 21, 2007 Author Share Posted May 21, 2007 Thanks So the following should work then, if (preg_match("65\.54\.188.\(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", $ipaddress)) { $ipaddress = $ipaddress." - MSN Search Bot"; $user_name = "Bot"; } if (preg_match("65\.249\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).\(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", $ipaddress)) { $ipaddress = $ipaddress." - Google Crawler Bot"; $user_name = "Bot"; } It should work but I get a delimiter error. Oops no I got it sorted now should be, if (preg_match("/65.54.188.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ipaddress)) { $ipaddress = $ipaddress." - MSN Search Bot"; $user_name = "Bot"; } if (preg_match("/65.249.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/", $ipaddress)) { $ipaddress = $ipaddress." - Google Crawler Bot"; $user_name = "Bot"; } Cheers for your help! Quote Link to comment https://forums.phpfreaks.com/topic/52315-solved-ip-part-match/#findComment-258130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.