forked from ircfspace/cf2dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawler.php
55 lines (51 loc) · 2.28 KB
/
crawler.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
<?php
function get_optimization_ip($type='v4') {
$KEY = 'o1zrmHAF';
try {
$headers = array('Content-Type: application/json');
$data = array("key" => $KEY, "type" => $type);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.hostmonit.com/get_optimization_ip');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_status == 200) {
return json_decode($response, true);
} else {
echo "CHANGE OPTIMIZATION IP ERROR: REQUEST STATUS CODE IS NOT 200\n";
return null;
}
curl_close($ch);
} catch (Exception $e) {
echo "CHANGE OPTIMIZATION IP ERROR: " . $e->getMessage() . "\n";
return null;
}
}
$getListIpv4 = get_optimization_ip();
$ipv4 = [];
if ( isset($getListIpv4['code'], $getListIpv4['total']) &&
$getListIpv4['code'] === 200 && $getListIpv4['total'] > 0 ) {
foreach ($getListIpv4['info'] as $key => $l) {
$ipv4 = array_merge($ipv4, $l);
}
file_put_contents("list/ipv4.json", json_encode(array_slice($ipv4, 0, 25), JSON_PRETTY_PRINT));
}
$getListIpv6 = get_optimization_ip('v6');
$ipv6 = [];
if ( isset($getListIpv6['code'], $getListIpv6['total']) &&
$getListIpv6['code'] === 200 && $getListIpv6['total'] > 0 ) {
foreach ($getListIpv6['info'] as $key => $l) {
$ipv6 = array_merge($ipv6, $l);
}
file_put_contents("list/ipv6.json", json_encode(array_slice($ipv6, 0, 25), JSON_PRETTY_PRINT));
}
$ips = [];
if ( !empty($ipv4) && !empty($ipv6) ) {
$ips['ipv4'] = $ipv4;
$ips['ipv6'] = $ipv6;
file_put_contents("list/export.json", json_encode(array_slice($ips, 0, 25), JSON_PRETTY_PRINT));
}