diff --git a/src/IPinfo.php b/src/IPinfo.php index af76b82..bf3cc20 100644 --- a/src/IPinfo.php +++ b/src/IPinfo.php @@ -134,6 +134,34 @@ public function getRequestDetails(string $ip_address) return $raw_details; } + /** + * Gets a URL to a map on https://ipinfo.io/map given a list of IPs (max + * 500,000). + * @param array $ips list of IP addresses to put on the map. + * @return string URL to the map. + */ + public function getMapUrl($ips) + { + $url = sprintf("%s/map?cli=1", self::API_URL); + + try { + $response = $this->http_client->request( + 'POST', + $url, + [ + 'json' => $ips + ] + ); + } catch (GuzzleException $e) { + throw new IPinfoException($e->getMessage()); + } catch (Exception $e) { + throw new IPinfoException($e->getMessage()); + } + + $res = json_decode($response->getBody(), true); + return $res['reportUrl']; + } + /** * Build headers for API request. * @return array Headers for API request. @@ -165,7 +193,7 @@ private function readCountryNames($countries_file) /** * Returns a versioned cache key given a user-input key. - * @param string key to transform into a versioned cache key. + * @param string $k key to transform into a versioned cache key. * @return string the versioned cache key. */ private function cacheKey($k) diff --git a/tests/IPinfoTest.php b/tests/IPinfoTest.php index 007cdc7..cf11a34 100644 --- a/tests/IPinfoTest.php +++ b/tests/IPinfoTest.php @@ -134,4 +134,12 @@ public function testGuzzleOverride() $this->expectException(IPinfoException::class); $res = $h->getDetails($ip); } + + public function testGetMapURL() + { + $h = new IPinfo(); + $url = $h->getMapUrl(file("tests/map-ips.txt")); + echo "got URL=".$url; + $this->assertStringStartsWith("https://ipinfo.io/map/", $url); + } } diff --git a/tests/map-ips.txt b/tests/map-ips.txt new file mode 100644 index 0000000..ff60b2c --- /dev/null +++ b/tests/map-ips.txt @@ -0,0 +1,1000 @@ +229.246.62.100 +58.216.129.161 +172.155.169.75 +101.59.211.185 +225.198.216.214 +133.158.185.202 +204.168.65.183 +152.217.109.105 +89.220.150.154 +23.172.32.183 +140.134.204.79 +200.17.104.175 +39.211.70.31 +85.245.244.4 +109.64.196.135 +52.173.54.52 +169.141.188.203 +47.55.111.20 +83.169.77.68 +59.209.226.43 +210.31.5.80 +237.185.230.88 +119.80.133.195 +32.252.135.244 +30.201.250.220 +139.219.17.112 +131.77.225.68 +49.24.39.2 +130.100.0.1 +183.243.120.226 +122.42.181.172 +11.110.160.145 +209.60.32.26 +155.223.149.123 +154.217.246.42 +188.109.113.174 +230.249.25.49 +39.18.158.167 +194.134.131.163 +14.58.214.99 +152.77.39.203 +235.240.120.33 +235.128.34.111 +29.54.183.51 +190.113.7.56 +66.104.113.67 +172.243.84.139 +102.79.131.76 +250.192.227.34 +83.114.246.136 +88.208.76.114 +165.26.163.126 +165.107.5.23 +202.178.174.224 +75.80.1.84 +164.240.158.55 +115.204.198.65 +186.7.193.125 +195.220.136.14 +64.24.109.136 +228.31.123.246 +12.81.63.171 +144.209.152.180 +84.248.98.182 +84.107.174.126 +166.232.66.212 +210.11.83.23 +123.217.137.164 +66.213.57.213 +162.40.80.97 +250.65.21.199 +104.240.141.39 +54.232.37.3 +172.247.123.193 +33.161.101.59 +164.59.123.140 +180.29.8.174 +54.111.248.46 +130.167.5.143 +144.72.154.192 +169.112.138.93 +237.109.165.78 +182.46.86.51 +206.184.230.72 +40.66.3.177 +51.160.61.151 +154.10.102.67 +184.168.78.158 +184.42.131.109 +8.162.101.192 +215.54.233.37 +168.122.243.130 +119.5.203.202 +162.222.107.169 +37.26.205.29 +167.160.66.93 +30.178.226.77 +73.200.246.249 +139.126.78.229 +20.106.82.172 +211.146.203.88 +10.164.255.210 +19.43.240.84 +203.159.123.96 +53.55.165.73 +119.32.42.121 +9.247.160.186 +21.37.46.219 +42.104.40.57 +183.38.62.38 +153.167.151.120 +12.104.241.34 +180.70.81.244 +67.0.195.231 +89.206.3.18 +158.245.158.43 +34.99.192.118 +10.158.92.109 +250.43.122.195 +229.168.220.100 +41.7.53.61 +62.4.110.186 +158.17.222.43 +146.245.202.226 +19.152.75.189 +94.140.121.233 +213.43.53.42 +144.210.191.16 +29.214.121.106 +178.6.13.189 +74.111.144.100 +51.160.109.149 +88.12.68.249 +196.9.155.128 +118.102.164.236 +240.238.81.232 +186.229.17.176 +78.55.251.1 +212.226.230.75 +47.86.60.114 +175.219.30.55 +249.44.136.155 +71.186.76.98 +126.37.66.173 +153.99.179.246 +237.17.109.181 +205.106.59.105 +156.232.215.199 +108.179.44.99 +137.224.141.96 +183.56.146.127 +174.253.253.112 +219.99.58.80 +111.53.64.162 +54.163.71.194 +112.65.100.52 +116.123.144.241 +191.185.208.24 +47.170.24.16 +214.37.218.169 +99.157.23.118 +70.155.33.250 +43.197.144.100 +41.226.114.93 +78.42.245.179 +88.47.128.82 +122.147.189.22 +63.26.103.120 +68.130.91.172 +108.46.17.125 +182.142.78.223 +128.251.99.208 +235.198.219.129 +55.122.118.236 +161.9.50.170 +204.132.171.154 +249.18.172.92 +28.221.41.85 +75.57.30.210 +156.107.69.57 +231.212.53.99 +213.52.87.79 +80.146.251.104 +162.184.118.8 +86.26.110.81 +7.211.220.91 +178.250.34.166 +178.118.207.196 +54.233.210.96 +47.228.85.31 +228.241.35.149 +115.9.43.89 +194.232.145.53 +39.207.207.204 +32.220.115.213 +176.30.220.222 +45.99.213.222 +16.27.10.75 +72.52.109.159 +82.34.221.10 +141.200.89.185 +22.124.27.116 +133.204.131.231 +238.227.59.69 +111.220.65.238 +250.131.93.245 +175.29.41.220 +237.5.12.203 +216.64.33.107 +147.224.143.141 +186.98.170.68 +42.98.191.67 +148.45.250.244 +248.225.6.0 +122.25.164.40 +162.19.72.9 +144.220.89.122 +160.90.198.17 +87.91.2.187 +53.99.76.185 +205.75.242.175 +168.215.105.127 +159.213.175.145 +131.32.114.191 +123.181.89.34 +198.68.34.149 +150.57.57.73 +96.154.120.244 +204.30.231.89 +234.163.230.187 +131.182.84.79 +207.227.6.88 +94.207.45.255 +170.72.174.15 +66.11.157.205 +41.143.150.221 +154.21.168.16 +206.248.218.104 +143.18.167.201 +116.54.253.155 +201.62.187.170 +31.85.104.253 +227.236.57.77 +239.100.152.67 +228.67.74.234 +78.245.182.129 +73.13.165.193 +11.207.254.225 +68.8.99.81 +209.56.87.209 +39.224.191.53 +48.136.38.139 +121.211.209.168 +13.9.126.207 +169.219.153.16 +131.106.248.117 +224.32.146.0 +84.195.60.125 +24.162.212.26 +154.207.29.231 +112.57.38.177 +3.205.185.222 +242.187.86.39 +251.98.109.145 +248.12.101.52 +79.184.111.126 +249.175.157.211 +148.16.183.41 +170.26.30.178 +178.76.190.16 +240.109.26.60 +195.53.53.112 +30.72.73.110 +107.33.114.42 +213.220.64.116 +39.113.151.56 +10.11.0.30 +148.7.242.88 +86.215.122.231 +53.180.85.144 +200.148.118.236 +116.197.252.71 +154.130.247.247 +7.97.64.221 +183.168.146.206 +116.187.37.192 +69.203.74.82 +18.240.247.126 +89.47.37.21 +93.159.27.84 +37.147.26.238 +41.155.158.66 +2.236.128.203 +36.178.197.120 +91.224.169.194 +53.168.145.33 +28.101.111.74 +92.135.87.144 +174.12.247.37 +90.186.57.227 +69.129.100.238 +125.42.204.236 +93.216.110.171 +159.153.127.132 +73.192.125.146 +168.205.243.134 +235.59.149.124 +27.245.15.254 +137.233.83.233 +74.3.149.200 +231.45.84.30 +38.191.50.235 +8.123.15.197 +240.220.130.7 +110.148.238.235 +161.168.69.89 +53.161.191.10 +188.216.180.230 +57.31.146.128 +37.99.183.100 +196.27.223.176 +59.184.53.117 +222.198.59.204 +122.89.221.133 +144.138.118.90 +221.111.139.70 +195.185.65.185 +117.223.0.193 +7.234.75.33 +157.6.155.191 +132.89.194.175 +74.106.66.157 +56.19.228.147 +93.89.45.62 +58.208.150.190 +216.235.34.27 +146.132.87.219 +124.44.27.126 +137.187.14.8 +41.230.122.179 +65.195.77.185 +30.214.247.64 +96.49.232.79 +164.67.163.117 +132.196.128.249 +248.222.243.182 +238.206.246.164 +103.179.190.170 +83.201.58.96 +239.178.77.197 +254.10.35.235 +116.159.72.189 +253.77.171.248 +58.183.11.93 +220.43.59.45 +11.229.165.166 +212.29.241.248 +137.21.48.186 +57.245.139.234 +221.200.237.181 +137.62.236.141 +119.131.158.152 +208.173.237.72 +122.29.173.209 +77.151.222.10 +62.246.195.150 +71.31.127.180 +172.174.187.80 +140.152.244.19 +74.254.83.53 +225.81.216.135 +99.26.120.8 +150.200.247.202 +73.99.93.23 +19.201.30.151 +32.87.50.149 +106.221.199.45 +138.182.53.235 +49.191.234.67 +103.58.111.11 +64.128.133.224 +146.132.32.252 +157.207.194.234 +24.222.203.230 +205.123.11.35 +43.255.128.199 +29.216.249.230 +217.197.199.58 +37.153.32.173 +187.104.200.64 +38.210.146.174 +211.168.153.179 +182.96.13.139 +169.141.203.60 +169.141.140.189 +12.51.251.124 +149.202.133.195 +113.170.40.7 +72.165.79.38 +252.10.236.1 +150.127.5.228 +14.206.76.103 +238.46.94.136 +37.241.120.30 +225.54.103.118 +71.6.179.221 +56.14.203.91 +182.165.133.185 +33.61.180.23 +107.187.22.42 +165.70.40.228 +192.160.239.33 +235.66.61.185 +143.37.84.133 +161.234.163.137 +48.154.252.21 +94.215.140.116 +74.152.100.20 +28.240.64.57 +89.213.87.224 +26.69.254.52 +103.233.61.39 +6.61.108.34 +11.109.218.113 +130.71.176.90 +180.135.100.18 +84.143.146.212 +251.34.85.138 +114.209.247.108 +247.49.114.19 +139.16.15.253 +196.211.105.226 +180.30.81.41 +22.97.60.74 +202.53.29.147 +198.169.152.125 +141.38.114.252 +27.141.185.184 +160.156.13.130 +11.247.53.86 +198.158.157.53 +166.227.233.117 +180.180.188.148 +128.92.177.93 +49.144.137.118 +58.146.97.72 +36.30.202.190 +52.252.49.247 +34.244.209.222 +212.85.246.6 +97.139.205.120 +84.83.118.55 +10.147.187.186 +33.192.137.151 +193.29.188.157 +128.108.144.192 +123.218.107.237 +226.235.108.38 +245.172.8.105 +60.205.46.68 +43.164.248.190 +172.196.13.138 +111.136.96.200 +242.146.61.111 +87.174.238.238 +244.81.44.208 +222.244.95.137 +122.229.192.77 +175.158.158.246 +221.136.180.34 +155.251.216.30 +103.189.118.78 +202.16.35.52 +8.111.132.68 +226.218.72.28 +169.33.1.105 +240.195.53.31 +169.200.148.29 +124.93.156.178 +190.29.106.213 +185.82.1.11 +10.149.6.50 +174.225.234.111 +54.143.157.151 +251.209.49.17 +70.19.40.97 +76.193.184.190 +236.201.144.33 +227.140.121.72 +77.113.24.227 +230.178.46.56 +1.127.176.39 +158.173.84.198 +18.71.174.39 +50.61.249.244 +26.228.255.84 +221.205.150.239 +110.239.18.82 +25.141.209.172 +101.208.111.125 +240.188.221.161 +39.163.237.194 +215.83.99.146 +21.234.53.186 +64.188.10.128 +250.85.171.177 +134.98.134.147 +227.161.54.150 +136.151.107.65 +69.228.152.85 +147.40.108.116 +181.161.122.24 +152.215.237.85 +60.104.183.46 +236.51.115.211 +192.60.164.147 +223.21.137.224 +177.153.122.210 +227.249.103.250 +247.80.233.81 +249.250.39.154 +85.205.137.222 +23.152.30.176 +110.157.165.165 +52.157.147.82 +113.227.204.128 +100.198.140.26 +169.117.135.99 +122.246.201.212 +200.63.99.98 +146.91.103.201 +210.67.37.239 +110.220.30.13 +76.33.105.79 +196.192.241.56 +204.82.20.133 +162.100.51.38 +132.231.18.248 +49.254.211.215 +2.251.213.168 +226.29.194.117 +46.108.245.11 +254.103.60.143 +127.17.236.202 +253.160.236.88 +107.28.58.4 +210.134.127.95 +84.193.220.248 +87.44.18.206 +89.253.94.193 +98.3.126.133 +139.163.201.154 +115.24.163.122 +55.44.221.177 +216.142.114.69 +96.11.112.96 +230.73.16.143 +93.16.62.136 +244.110.3.20 +209.148.123.44 +33.39.159.130 +60.90.236.154 +100.3.184.39 +144.72.248.202 +57.243.151.182 +118.17.143.229 +70.242.29.140 +21.182.114.7 +227.2.74.32 +43.24.7.156 +54.121.134.88 +51.8.30.3 +152.80.81.31 +156.122.57.91 +4.246.169.215 +254.201.59.224 +99.212.162.99 +193.79.241.130 +226.42.247.178 +31.188.164.63 +28.153.85.109 +33.193.57.73 +105.211.148.43 +16.117.233.195 +203.202.131.170 +250.133.241.184 +133.105.58.10 +92.159.22.168 +220.65.55.233 +219.187.6.24 +142.236.166.89 +232.24.95.44 +166.251.143.128 +82.50.137.166 +193.190.136.12 +85.17.79.143 +0.152.102.133 +80.75.39.126 +66.35.44.186 +53.216.150.133 +147.23.187.200 +217.202.211.20 +36.12.133.19 +78.21.99.24 +109.62.223.164 +148.219.50.45 +0.19.115.213 +177.126.94.202 +123.178.58.132 +95.77.142.85 +135.209.183.74 +10.86.10.172 +38.50.64.131 +29.231.110.111 +193.101.230.194 +58.93.43.80 +46.68.95.200 +24.250.117.19 +118.136.154.21 +84.71.42.21 +76.203.147.139 +70.77.253.183 +210.50.53.117 +205.169.38.164 +87.237.144.90 +39.90.168.7 +113.101.48.59 +115.103.177.223 +118.136.8.120 +235.138.249.93 +199.162.8.147 +48.88.166.224 +28.117.255.42 +135.43.106.187 +202.82.151.210 +59.118.181.237 +237.101.102.220 +83.251.255.206 +109.143.28.212 +194.115.161.175 +203.74.246.97 +29.52.136.188 +15.173.246.246 +153.181.243.77 +165.246.30.232 +247.6.234.152 +162.155.162.71 +151.12.238.53 +14.4.9.187 +8.102.27.20 +103.54.1.200 +127.115.198.109 +156.125.44.248 +101.110.157.35 +12.114.78.205 +47.237.196.201 +120.78.219.158 +0.28.115.48 +64.124.86.18 +15.221.164.139 +252.115.7.116 +254.21.41.159 +195.177.84.62 +128.57.0.115 +141.227.110.218 +19.53.1.146 +15.207.134.0 +63.119.141.187 +143.252.150.225 +237.108.242.141 +195.12.192.91 +47.134.126.30 +59.217.108.94 +37.145.173.12 +146.252.40.0 +70.111.206.184 +127.176.104.125 +164.155.48.45 +208.124.190.35 +71.83.243.96 +162.107.126.106 +223.151.69.198 +159.142.199.179 +217.229.67.136 +154.185.174.85 +32.207.211.172 +13.126.35.74 +73.97.71.39 +3.71.183.9 +218.126.101.129 +63.17.193.113 +197.243.37.141 +86.69.245.88 +75.194.149.223 +114.137.73.226 +84.136.12.112 +199.112.25.23 +63.171.233.20 +119.150.71.180 +157.26.81.60 +175.249.143.154 +93.63.224.148 +75.134.162.159 +174.85.118.221 +247.245.141.238 +195.224.124.55 +40.249.101.33 +16.45.61.104 +91.37.225.214 +86.227.38.132 +177.47.50.182 +241.188.66.89 +226.168.132.51 +82.111.190.10 +200.18.215.174 +193.25.57.144 +29.178.152.239 +15.213.164.181 +7.145.44.16 +43.209.31.12 +109.152.223.170 +73.167.117.195 +79.113.86.235 +201.93.122.11 +59.110.29.80 +175.53.95.22 +103.156.1.112 +138.152.167.235 +29.182.204.60 +93.177.203.12 +217.52.152.71 +197.97.216.163 +222.117.53.197 +111.110.109.202 +16.105.24.204 +55.40.80.144 +39.164.234.118 +159.142.220.135 +253.81.233.190 +123.7.175.121 +243.9.173.218 +135.13.169.5 +253.47.214.246 +209.236.140.196 +180.104.193.106 +220.142.233.1 +130.237.159.55 +55.87.150.93 +35.167.135.0 +49.175.253.154 +151.9.244.179 +148.182.22.212 +127.152.61.68 +63.10.219.107 +73.226.17.217 +65.170.201.234 +177.247.196.135 +82.132.251.71 +207.187.189.112 +42.60.88.48 +7.45.40.99 +63.3.139.120 +142.155.3.199 +149.139.162.4 +11.8.205.150 +54.250.126.237 +155.126.248.108 +27.114.116.231 +246.238.83.154 +28.111.246.161 +220.28.39.102 +211.119.119.13 +110.151.56.253 +33.166.218.74 +242.158.42.212 +196.36.80.203 +168.69.104.93 +95.185.233.70 +160.17.218.160 +162.68.213.231 +118.45.49.35 +90.71.64.104 +53.241.119.216 +149.244.45.22 +101.169.54.172 +11.11.59.197 +146.93.181.33 +0.70.162.5 +82.188.216.160 +47.234.217.224 +83.207.177.224 +127.137.53.201 +1.177.165.53 +91.62.136.177 +148.231.40.1 +173.225.12.246 +20.85.74.39 +165.123.221.203 +159.201.26.37 +161.173.80.23 +23.73.80.64 +129.138.38.6 +49.213.9.199 +21.205.181.205 +182.21.220.196 +21.248.178.223 +187.1.212.239 +48.129.47.248 +185.62.244.30 +249.160.232.240 +146.224.242.7 +81.40.178.29 +243.58.84.178 +28.21.2.247 +187.105.40.192 +83.135.88.70 +216.109.114.230 +196.108.63.59 +115.128.71.226 +26.12.101.71 +188.105.253.57 +89.54.241.101 +211.73.9.143 +60.164.196.203 +126.156.25.155 +131.173.76.40 +209.208.165.151 +223.223.180.247 +98.177.114.250 +126.210.144.150 +67.190.138.36 +25.211.164.156 +89.125.179.43 +16.240.48.151 +56.250.111.55 +17.72.56.111 +121.72.100.167 +102.103.148.83 +107.122.199.65 +158.243.58.184 +110.102.5.247 +19.2.140.112 +106.199.144.238 +96.63.216.255 +205.120.16.159 +62.28.12.135 +12.0.181.104 +217.124.0.153 +145.7.140.128 +107.153.137.129 +89.114.130.77 +205.16.144.74 +85.237.255.234 +123.6.81.221 +5.119.183.0 +6.34.127.135 +54.45.59.242 +144.128.233.150 +127.234.81.195 +3.128.61.148 +25.170.37.16 +105.215.210.139 +31.54.66.151 +48.197.34.91 +53.80.156.203 +223.147.165.218 +29.71.80.157 +9.225.224.145 +62.233.61.127 +107.25.15.1 +195.91.98.237 +154.104.191.54 +251.252.18.8 +65.243.105.114 +124.254.223.42 +144.197.175.51 +241.244.83.62 +96.175.248.46 +234.15.71.238 +17.243.42.38 +243.119.240.203 +92.9.101.166 +7.151.71.107 +104.25.250.94 +136.167.166.31 +61.3.117.39 +126.193.118.4 +79.183.113.121 +217.206.44.42 +121.65.146.72 +67.186.170.206 +178.125.253.45 +120.89.116.38 +214.241.211.103 +184.43.192.111 +48.5.33.89 +180.61.179.216 +154.25.184.21 +234.236.169.10 +46.73.237.76 +204.172.243.172 +62.94.64.181 +248.126.176.233 +191.18.61.53 +235.71.227.39 +214.210.173.37 +237.78.23.77 +117.20.11.193 +127.205.66.210 +51.42.141.236 +37.196.192.225 +229.186.100.18 +205.218.245.61 +47.187.91.225 +117.41.97.78 +221.24.47.150 +180.176.104.153 +112.36.65.214 +147.20.10.212 +19.89.191.211 +165.108.56.235 +42.26.172.145 +122.126.106.108 +21.242.77.81 +42.224.153.68 +93.48.217.151 +128.139.219.34 +114.65.254.82 +173.0.231.92 +234.207.104.2 +250.10.147.108 +251.139.228.125 +44.78.235.100 +98.212.20.60 +51.252.156.192 +139.65.137.12 +66.24.171.202 +85.51.148.203 +25.59.65.92 +77.206.101.189 +217.156.99.132 +20.120.246.35 +196.134.109.98 +216.158.96.137 +79.98.7.102 +91.124.87.168 +103.100.92.175 +122.19.84.168 +34.254.42.152 +90.175.197.87 +177.65.118.106 +172.249.181.182 +123.201.249.102 +149.103.209.106 +157.16.37.48 +159.75.170.144 +32.124.64.254 +153.44.89.111 +38.228.111.170 +172.98.157.70 +214.215.96.62 +46.231.128.136 +16.187.181.229 +230.193.252.41 +194.20.128.250 +254.237.150.16 +60.85.83.49 +57.71.241.178 +12.43.166.153 +86.100.91.105 +75.55.213.73 +36.166.185.44 +16.44.242.174 +163.228.203.230 +47.13.131.155 +238.80.102.233 +180.4.40.171 +23.57.70.133 +50.24.84.5 +190.122.43.230 +150.213.147.146 +5.155.72.135 +127.255.127.137 +107.24.244.137 +163.125.190.118 +32.12.119.17 +14.19.101.87 +142.97.18.252 +220.119.208.96 +185.191.82.108 +92.178.29.16 +29.52.223.57 +118.184.197.112 +40.27.53.69 +188.176.54.49 +178.138.20.41 +204.215.172.131 +237.252.207.111 +12.221.126.228 +227.238.109.51