-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_usage.php
More file actions
108 lines (94 loc) · 3.56 KB
/
advanced_usage.php
File metadata and controls
108 lines (94 loc) · 3.56 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use IPLocate\Exceptions\AuthenticationException;
use IPLocate\Exceptions\InvalidIPException;
use IPLocate\Exceptions\NotFoundException;
use IPLocate\Exceptions\RateLimitException;
use IPLocate\IPLocate;
// Get your free API key from https://iplocate.io/signup
$apiKey = 'your-api-key-here';
try {
// Create client with custom configuration
$client = new IPLocate(
apiKey: $apiKey,
timeout: 60.0
);
// Look up your own IP
echo "=== Your IP Information ===\n";
$selfResult = $client->lookupSelf();
echo "Your IP: {$selfResult->ip}\n";
if ($selfResult->country) {
echo "Country: {$selfResult->country} ({$selfResult->countryCode})\n";
}
if ($selfResult->city) {
echo "City: {$selfResult->city}\n";
}
echo "\n=== Google DNS Information ===\n";
$googleResult = $client->lookup('8.8.8.8');
// Geographic information
if ($googleResult->latitude && $googleResult->longitude) {
echo "Coordinates: {$googleResult->latitude}, {$googleResult->longitude}\n";
}
if ($googleResult->timeZone) {
echo "Timezone: {$googleResult->timeZone}\n";
}
if ($googleResult->currencyCode) {
echo "Currency: {$googleResult->currencyCode}\n";
}
if ($googleResult->callingCode) {
echo "Calling code: +{$googleResult->callingCode}\n";
}
// ASN information
if ($googleResult->asn) {
echo "\n--- ASN Information ---\n";
echo "ASN: {$googleResult->asn->asn}\n";
echo "ISP: {$googleResult->asn->name}\n";
echo "Network: {$googleResult->asn->route}\n";
echo "Type: {$googleResult->asn->type}\n";
}
// Company information
if ($googleResult->company) {
echo "\n--- Company Information ---\n";
echo "Name: {$googleResult->company->name}\n";
echo "Domain: {$googleResult->company->domain}\n";
echo "Type: {$googleResult->company->type}\n";
}
// Privacy and threat detection
echo "\n--- Privacy & Threat Detection ---\n";
echo 'VPN: ' . ($googleResult->privacy->isVpn ? 'Yes' : 'No') . "\n";
echo 'Proxy: ' . ($googleResult->privacy->isProxy ? 'Yes' : 'No') . "\n";
echo 'Tor: ' . ($googleResult->privacy->isTor ? 'Yes' : 'No') . "\n";
echo 'Hosting: ' . ($googleResult->privacy->isHosting ? 'Yes' : 'No') . "\n";
echo 'Anonymous: ' . ($googleResult->privacy->isAnonymous ? 'Yes' : 'No') . "\n";
// Hosting information
if ($googleResult->hosting) {
echo "\n--- Hosting Information ---\n";
if ($googleResult->hosting->provider) {
echo "Provider: {$googleResult->hosting->provider}\n";
}
if ($googleResult->hosting->service) {
echo "Service: {$googleResult->hosting->service}\n";
}
}
// Abuse contact information
if ($googleResult->abuse) {
echo "\n--- Abuse Contact ---\n";
if ($googleResult->abuse->email) {
echo "Email: {$googleResult->abuse->email}\n";
}
if ($googleResult->abuse->name) {
echo "Name: {$googleResult->abuse->name}\n";
}
}
} catch (InvalidIPException $e) {
echo "Invalid IP address: {$e->getMessage()}\n";
} catch (AuthenticationException $e) {
echo "Authentication error: {$e->getMessage()}\n";
} catch (NotFoundException $e) {
echo "IP not found: {$e->getMessage()}\n";
} catch (RateLimitException $e) {
echo "Rate limit exceeded: {$e->getMessage()}\n";
} catch (\Exception $e) {
echo "Unexpected error: {$e->getMessage()}\n";
}