chrislim2888 / IP2Location-PHP-Module

This module is a PHP module that enables the user to find the country, region, city, coordinates, zip code, ISP, domain name, timezone, connection speed, IDD code, area code, weather station code, weather station name, mobile, usage types, address type, IAB category, etc that any IP address or host name originates from.
https://www.ip2location.com
MIT License
197 stars 69 forks source link

IP_FROM #18

Closed bazooka07 closed 6 years ago

bazooka07 commented 6 years ago

I have written a nice program with Python to setup .htaccess with "Deny from IP_address" I post it here on Github: https://gist.github.com/bazooka07/5e743e2572fec54b6e1f81f60263da0a Obviously, it can't run directly with Apache. I wish to do the same task but in PHP. How can I get the IP_FROM address after calling \IP2Location\Database::lookup($ip) ?

I need to get CIDR like this : \IP2Location\Database::lookup('178.159.37.18') ---> 178.159.37.0/24 I can easily get ip_from in Python '178.159.37.0' but I can't get it with PHP

If I can get this missing part, I can do the rest $ipNum = ip2long('178.159.37.0'); $i=32; $mask=1; while(($ipNum & $mask) == 0) {$mask *= 2; $i--;}; echo $i;

Help me , please.

chrislim2888 commented 6 years ago

I'm sorry that you can't get the ip_from through this PHP module. You can load the CSV file into a database to retrieve the ip_from value, instead of using the BIN data file.

bazooka07 commented 6 years ago

Look at Pull Request #19