-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
39 lines (27 loc) · 912 Bytes
/
query.php
File metadata and controls
39 lines (27 loc) · 912 Bytes
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
<?php
//This function is more or less a copy from https://dns.hetzner.com/api-docs
function ip_query($sURL = "https://www.google.com") {
// Start a HTTP request outside of the local network via cURL to obtain the external IPv6 address
// get cURL resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $sURL);
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
// set a IPv6 query
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V6);
// send the request and save response to $response
$response = curl_exec($ch);
// stop if fails
if (!$response) {
die('Error IP check: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
// get own IP address
$response = curl_getinfo($ch, CURLINFO_LOCAL_IP);
// close curl resource to free up system resources
curl_close($ch);
return $response;
}
?>