-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathip.php
More file actions
executable file
·106 lines (93 loc) · 3.68 KB
/
ip.php
File metadata and controls
executable file
·106 lines (93 loc) · 3.68 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
<?php
# http://ipinfodb.com/
error_reporting(-1);
//require_once('src/geoip.inc');
//include("./src/geoip.inc");
//$gi = geoip_open("./GeoIPISP.dat",GEOIP_STANDARD);
if(empty($_GET['ip'])) $ip = $_SERVER['REMOTE_ADDR'];
else{
$ip = gethostbyname($_GET['ip']);
if(!filter_var($ip, FILTER_VALIDATE_IP)) $ip = $_SERVER['REMOTE_ADDR'];
}
$url = 'http://api.geoiplookup.net/?query=' . $ip;
$ipinfo = getipinfo($url);
$ip = $ipinfo['ip'];
$host = $ipinfo['host'];
$isp = $ipinfo['isp'];
$city = $ipinfo['city'];
$countrycode = $ipinfo['countrycode'];
$countryname = $ipinfo['countryname'];
$latitude = $ipinfo['latitude'];
$longitude = $ipinfo['longitude'];
//$record = geoip_record_by_name($ip);
//$timezone = geoip_time_zone_by_country_and_region($record['country_code'], $record['region']);
//$t = explode('/', $timezone);
//$continent = $t[0];
$title = '查找的IP为' . $ip;
$tdpre = "<tr><td><pre>";
$tdoff = "</pre></td></tr>";
$td = '</td><td> </td><td><pre>';
$html = '<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8">';
$html .= '<title>' .$title. '</title>';
$html .= '<style type="text/css">';
$html .= 'pre{border:dashed 1px green;padding:8px; background-color:#C1CDCD;color:#000000; font-size:15px}';
$html .= 'td{padding:2px;}';
$html .= '#search {width:300px;float:center;padding:1px;}';
$html .= '.searchbox {width:240px;padding:4px;font-size: 1em;}';
$html .= '.searchbtn {width:60px;padding:4px;background-color:green;border: 0;font-size: 16px;color:#000000;}';
$html .= '#content {float:center;}';
$html .= '</style></head>';
$html .= '<body><br><center><div id="search">';
$html .= '<b> 查找 IP 地址</b>';
$html .= '<form method="get" action="?ip=" id="searchform" onsubmit="return false;">';
$html .= '<input class="searchbox" type="text" name="ip" value="g.cn" />';
$html .= '<input class="searchbtn" type="submit" onclick="window.location.href=this.form.action + this.form.ip.value;" />';
$html .= '</form></div>';
$html .= '<div id="content"><br><b>' .$title. '</b><br>';
$html .= '<table width=300px>' . $tdpre . 'IP Address:' . $td . $ip . $tdoff;
$html .= $tdpre . 'Hostname:' . $td . $host . $tdoff;
$html .= $tdpre . 'ISP:' . $td . $isp . $tdoff;
$html .= $tdpre . 'Continent:' . $td . $continent . $tdoff;
$html .= $tdpre . 'Country:' . $td . $countryname . '(' .$countrycode. ')' . $tdoff;
$html .= $tdpre . 'City:' . $td . $city . $tdoff;
$html .= $tdpre . 'Timezone:' . $td . $timezone . $tdoff;
$html .= $tdpre . 'Latitude:' . $td . $latitude . $tdoff;
$html .= $tdpre . 'Longitude:' . $td . $longitude . $tdoff . '</table>';
$html .= '</div><center></body></html>';
echo ($html);
//echo beautify_html($html);
function getipinfo($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpCode == 404) return false;
else{
$xml = simplexml_load_string($data);
$array = (array)$xml;
$array = (array)$array['results'];
$res = (array)$array['result'];
return $res;
}
}
function beautify_html($html){
$tidy_config = array(
'clean' => false,
'indent' => true,
'indent-spaces' => 4,
'output-xhtml' => false,
'show-body-only' => false,
'wrap' => 0
);
if(function_exists('tidy_parse_string')){
$tidy = tidy_parse_string($html, $tidy_config, 'utf8');
$tidy -> cleanRepair();
return $tidy;
}
else return $html;
}