-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.IP2ProxyAPI.php
79 lines (68 loc) · 1.86 KB
/
class.IP2ProxyAPI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class IP2ProxyAPI
{
public $response;
public $ipAddress;
public $countryCode;
public $countryName;
public $regionName;
public $cityName;
public $isp;
public $domain;
public $usageType;
public $asn;
public $as;
public $lastSeen;
public $proxyType;
public $isProxy;
public $threat;
protected $apiKey;
protected $useSSL;
public function __construct($apiKey = '', $useSSL = false)
{
$this->apiKey = $apiKey;
$this->useSSL = $useSSL;
}
public function query($ip, $package = 'PX8')
{
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
return false;
}
$response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([
'key' => $this->apiKey,
'ip' => $ip,
'package' => $package,
'format' => 'json',
]));
if (($json = json_decode($response)) === null) {
return false;
}
$this->response = (string) $json->response;
$this->countryCode = (string) $json->countryCode;
$this->countryName = (string) $json->countryName;
$this->regionName = (string) $json->regionName;
$this->cityName = (string) $json->cityName;
$this->isp = (string) $json->isp;
$this->domain = (string) $json->domain;
$this->usageType = (string) $json->usageType;
$this->asn = (string) $json->asn;
$this->as = (string) $json->as;
$this->lastSeen = (string) $json->lastSeen;
$this->proxyType = (string) $json->proxyType;
$this->isProxy = (string) $json->isProxy;
$this->threat = (string) $json->threat;
return true;
}
private function get($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-3.0.0');
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$response = curl_exec($ch);
return $response;
}
}