# IPInfo testing Scripts to help test IPInfo `data_from_ip.php` ================== 1. Download https://gitlab.wikimedia.org/dwalden/ipinfo-testing/-/blob/main/data_from_ip.php 2. In the same directory, download https://github.com/maxmind/GeoIP2-php/releases/download/v2.11.0/geoip2.phar 3. In the same directory, download/move the GeoLite2 databases (the .mmdb files) 4. Run: `php data_from_ip.php ` (or if you use docker, instead run: `docker-compose exec mediawiki php data_from_ip.php `) `data_from_ip_enterprise.php` ================== This is very similar to the `data_from_ip.php` script, except it is for the MaxMind GeoIP2 Enterprise databases. 1. Download https://gitlab.wikimedia.org/dwalden/ipinfo-testing/-/blob/main/data_from_ip_enterprise.php 2. In the same directory, download https://github.com/maxmind/GeoIP2-php/releases/download/v2.11.0/geoip2.phar 3. In the same directory, download/move the GeoIP2 Enterprise databases (the .mmdb files) 4. Run: `php data_from_ip_enterprise.php ` (or if you use docker, instead run: `docker-compose exec mediawiki php data_from_ip_enterprise.php `) `erd_enterprise.php` ==================== This script will find IP addresses which return different datatypes from MaxMind. This could be used, for example, to test how IPInfo deals with null/empty/zero values. It will return a CSV. Each row has a different IP address plus all the "expected" values for that IP (based on what MaxMind returns). Each IP has a more-or-less unique combination of return values for each data point we are interested in (e.g. ISP, ASN, Connection Type). 1. Download https://gitlab.wikimedia.org/dwalden/ipinfo-testing/-/blob/main/erd_enterprise.php 2. In the same directory, download https://github.com/maxmind/GeoIP2-php/releases/download/v2.11.0/geoip2.phar 3. Download and extract the GeoIP2 Enterprise databases (called "GeoIP2 Anonymous IP" and "GeoIP2 Enterprise") and move the .mmdb files into the same directory 4. Download and extract "GeoIP2 Anonymous IP: CSV format" and "GeoIP2 Enterprise: CSV format" and move the .csv files into the same directory 5. Run: `php erd_enterprise.php ` (or if you use docker, instead run: `docker-compose exec mediawiki php erd_enterprise.php `) - Where `` is one of either `GeoIP2-Enterprise-Blocks-IPv4.csv` or `GeoIP2-Enterprise-Blocks-IPv6.csv` - `` is where the results will be written and can be called anything `ipinfo_api_response.py` ======================== This script will take the output .csv file generated by `erd_enterprise.php` and attempt to get output from IPInfo for the IP addresses listed in the .csv file. It assumes that there is at least one log entry associated with each IP address listed in the .csv file. You could, for example, block each IP address. It will output another .csv file with two rows for each IP address. One row lists the "expected" result, one the "actual" result. 1. Setup pywikibot using the instructions here https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation 2. Download and copy https://gitlab.wikimedia.org/dwalden/ipinfo-testing/-/blob/main/ipinfo_api_response.py into the `scripts/` directory in pywikibot 3. Run: `python3 pwb.py ipinfo_api_response -i -o -n -lang: -family:` - Where `` is the .csv file generated by `erd_enterprise.php` - `` and `` will depend on which environment you are testing IPInfo on `analyse_ipinfo_api_response.R` =============================== This R script which will help analyse the .csv file generated by `ipinfo_api_response.py`. It will test whether the "expected" and "actual" results match. It requires the R libraries `tidyr`, `dplyr` and `stringr`. `edit_from_ip.py` ================= This script simulates editing a wiki from any IP address you choose. The wiki you want to edit must have in its LocalSettings.php: $wgCdnServers = [ '$local_ip_address' ]; $wgUsePrivateIPs = true; where `$local_ip_address` is (I believe) your LAN IP address. If you use docker, you might instead want to add: $wgCdnServersNoPurge = [ '172.0.0.1/8' ]; $wgUsePrivateIPs = true; Then run: `python3 edit_from_ip.py -u $url -i $ip [-t $title]` Where: - `$url` is the URL of the wiki you want to test, including '/w/api.php' - `$ip` is the IP you want to simulate an edit from - `$title` is the page you want to edit (this is optional, if you don't pass this parameter it will edit the Main_Page) For example: `python3 edit_from_ip.py -u http://localhost:8080/w/api.php -i 1.2.3.4`