· 6 years ago · Mar 06, 2020, 01:52 AM
1
2 $ips = \DB::select("select distinct o.hostname from ouvintes o
3 left join geoip g on g.ip = o.hostname
4
5 where g.ip is null and o.hostname != '' limit 100");
6
7 foreach ($ips as $i) {
8
9 $curl = curl_init();
10
11 curl_setopt_array($curl, array(
12 CURLOPT_URL => "https://api.ipgeolocation.io/ipgeo?apiKey=e6f78d1727cf4d1cbeeca308b26ffbeb&ip=" . $i->hostname,
13 CURLOPT_RETURNTRANSFER => true,
14 CURLOPT_ENCODING => "",
15 CURLOPT_MAXREDIRS => 10,
16 CURLOPT_TIMEOUT => 30,
17 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
18 CURLOPT_CUSTOMREQUEST => "GET",
19 CURLOPT_HTTPHEADER => array(
20 "Accept: */*",
21 "Accept-Encoding: gzip, deflate",
22 "Cache-Control: no-cache",
23 "Connection: keep-alive",
24 "Cookie: __cfduid=d2e503eb958200ee30f79cd19dad03e391573663229",
25 "Host: api.ipgeolocation.io",
26 "Postman-Token: a6bda1ab-5047-44a6-8f7d-7b0b64a20a33,61072265-2418-48bc-8625-63cb71afff61",
27 "User-Agent: PostmanRuntime/7.19.0",
28 "cache-control: no-cache"
29 ),
30 ));
31
32 $response = curl_exec($curl);
33 $err = curl_error($curl);
34
35 curl_close($curl);
36
37 if ($err) {
38 echo "cURL Error #:" . $err;
39 } else {
40
41 $obj = json_decode($response, true);
42 if (!$obj) {
43 dump('estourou api key');
44 continue;
45 }
46 #$obj['organization'] = $this->clean($obj['organization']);
47 #$obj['district'] = $this->clean($obj['district']);
48 #$obj['state_prov'] = $this->clean($obj['state_prov']);
49 #dd($obj);
50 geoModel::create($obj);
51 dump('criou: ' . $i->hostname);
52 }
53 }