-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcip.php
87 lines (71 loc) · 2.23 KB
/
cip.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
80
81
82
83
84
85
86
<?php
use Alfred\Workflows\Workflow;
require_once ('vendor/Workflow.php');
require_once ('vendor/Result.php');
require_once ('util/request.php');
require ('util/ping.php');
const ICON = 'icon.png';
$wf = new Workflow;
function getIPData($ipr)
{
$response = request('https://free.is26.com/api/v1/getIp/' . urlencode($ipr));
$json = json_decode($response);
$result = $json->data;
return $result;
}
function getIp($q)
{
$ipNum = gethostbyname($q);
return $ipNum;
}
if (filter_var($query, FILTER_VALIDATE_IP))
{
$response = request('https://free.is26.com/api/v1/getIp/' . urlencode($query));
$json = json_decode($response);
$result = $json->data;
$ping = new Ping($result->ip);
$latency = $ping->ping();
$msTag = ' ms';
$wf->result()
->title($result->isp . ' ' . $result->area . ' ' . $result->region . ' ' . $result->city . ' ' . $result->country)
->subtitle($result->country_id . ' 延迟 ' . $latency . $msTag)->arg($result->isp . ' ' . $result->region . ' ' . $result->city . ' ' . $result->country)
->icon(ICON)
->autocomplete($key);
echo $wf->output();
}
else
{
if (strpos($query, '://') === false)
{
$query = 'http://' . $query;
}
$file_headers = @get_headers($query);
if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found')
{
$exists = false;
}
else
{
$host = parse_url($query);
$domain = $host['host'];
$ip = getIp($domain);
$latencyTag = ' 延迟';
$msTag = ' ms';
$response = request('https://free.is26.com/api/v1/getIp/' . urlencode($ip));
$json = json_decode($response);
$result = $json->data;
if (strpos($query, $ip) == true)
{
$ip = 'IP not found';
$latencyTag = '';
$msTag = '';
}
$ping = new Ping($ip);
$latency = $ping->ping();
$wf->result()
->title($result->isp . ' ' . $result->area . ' ' . $result->region . ' ' . $result->city . ' ' . $result->country)
->subtitle($ip . ' ' . $result->country_id . $latencyTag . $latency . $msTag)->arg($ip)->icon(ICON)
->autocomplete($key);
echo $wf->output();
}
}