-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
132 lines (111 loc) · 4.05 KB
/
api.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Api;
Class HeadRequest {
private static $valid_mac = "([0-9A-F]{2}[:-]){5}([0-9A-F]{2})"; /* patron de Mac Address */
private static $url = 'http://ip-api.com/json/'; /* Api */
public function userAgent () {
return $_SERVER['HTTP_USER_AGENT'];
}
public static function getIP () { /* Mostrar Ip Client 192.168.5.1 */
$server = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED'
];
foreach ($server as $value)
if (isset($_SERVER[$value])) return $_SERVER[$value];
return $_SERVER["REMOTE_ADDR"];
}
public function showDataIP ( $ip = null) { /* Mostrar ip y datos de localizacion */
if ($ip)
$data = file_get_contents(self::$url . $ip);
else
$data = file_get_contents(self::$url . self::getIP());
$json = json_decode($data, true);
return json_encode($json);
}
public function getPlatform () { /* Mostrar Sistema Operativo */
$platforms = [
'Windows 10' => 'Windows NT 10.0+',
'Windows 8.1' => 'Windows NT 6.3+',
'Windows 8' => 'Windows NT 6.2+',
'Windows 7' => 'Windows NT 6.1+',
'Windows Vista' => 'Windows NT 6.0+',
'Windows XP' => 'Windows NT 5.1+',
'Windows 2003' => 'Windows NT 5.2+',
'Windows Phone' => 'Windows Phone',
'Windows' => 'Windows otros',
'iPhone' => 'iPhone',
'iPad' => 'iPad',
'Mac OS X' => '(Mac OS X+)|(CFNetwork+)',
'Mac otros' => 'Macintosh',
'Android Jelly Bean' => 'Android 4.1.2',
'Android' => 'Android',
'BlackBerry' => 'BlackBerry',
'Linux ' => 'Linux',
];
foreach( $platforms as $platform => $pattern )
if (eregi($pattern, self::userAgent())) return $platform;
return 'Otras';
}
public static function getBrowser () { /* Mostrar Navegador */
$browsers = [
'Maxthon' => 'Maxthon',
'SeaMonkey' => 'SeaMonkey',
'Vivaldi' => 'Vivaldi',
'Arora' => 'Arora',
'Avant Browser' => 'Avant Browser',
'Beamrise' => 'Beamrise',
'Epiphany' => 'Epiphany',
'Chromium' => 'Chromium',
'Iceweasel' => 'Iceweasel',
'Galeon' => 'Galeon',
'Edge' => 'Microsoft Edge',
'Trident' => 'Internet Explorer', //IE 11
'MSIE' => 'Internet Explorer',
'Opera Mini' => 'Opera Mini',
'Opera' => 'Opera',
'OPR' => 'Opera',
'Firefox' => 'Mozilla Firefox',
'Chrome' => 'Google Chrome',
'Safari' => 'Safari',
'iTunes' => 'iTunes',
'Konqueror' => 'Konqueror',
'Dillo' => 'Dillo',
'Netscape' => 'Netscape',
'Midori' => 'Midori',
'ELinks' => 'ELinks',
'Links' => 'Links',
'Lynx' => 'Lynx',
'w3m' => 'w3m',
'Browser Unknown' => 'Browser Unknown'
];
foreach ($browsers as $key => $value)
if (strpos(' ' . self::userAgent(), $key)) return $value;
return $browsers['Browser Unknown'];
}
protected static function runCommand($command) { /* ejecuto command */
return shell_exec($command);
}
public static function getCurrentMacAddress () { /* Mostrar Mac Address */
$ifconfig = self::runCommand("ifconfig eth0");
preg_match("/" . self::$valid_mac . "/i", $ifconfig, $ifconfig);
if (isset($ifconfig[0])) {
return trim(strtoupper($ifconfig[0]));
}
return false;
}
public static function headDataRequest () { /* Mostrar datos completos ip, localizacion, navegador, Sistema Operativo y Mac Address */
$data = json_decode(self::showDataIP('186.90.129.247'), true);
if (!$data)
$data = json_decode(self::showDataIP(), true);
$data['ip'] = $data['query'];
$data['Browser'] = self::getBrowser();
$data['Platform'] = self::getPlatform();
$data['MacAddress'] = self::getCurrentMacAddress();
unset($data['query']);
return json_encode($data);
}
}