-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfip.php
130 lines (104 loc) · 3.27 KB
/
cfip.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
<?php
require_once("cfgeo.php");
require_once("functions.php");
$today_date = date("F j");
$today_year = date("Y");
$today_time = date("g:i a");
//$log = preg_replace('/\s+/', '', $today);
$logfile = "/var/www/tyclifford/dec-ip_b-test.csv";
$agent = $_SERVER["HTTP_USER_AGENT"];
$uri = $_SERVER['REQUEST_URI'];
if( preg_match('/MSIE (\d+\.\d+);/', $agent) ) {
$browser = "Internet Explorer";
} else if (preg_match('/Chrome[\/\s](\d+\.\d+)/', $agent) ) {
$browser = "Chrome";
} else if (preg_match('/Edge\/\d+/', $agent) ) {
$browser = "Edge";
} else if ( preg_match('/Firefox[\/\s](\d+\.\d+)/', $agent) ) {
$browser = "Firefox";
} else if ( preg_match('/OPR[\/\s](\d+\.\d+)/', $agent) ) {
$browser = "Opera";
} else if (preg_match('/Safari[\/\s](\d+\.\d+)/', $agent) ) {
$browser = "Safari";
}
function get_ip(){
if( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ){
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
elseif( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function get_real_ip(){
// Get IP Address
$ip = get_ip();
if( function_exists( 'is_cloudflare' ) ){
if( is_cloudflare() ) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
}
return strip_tags( $ip );
}
function ip_in_range( $ip, $range ){
if ( mb_strpos( $range, '/' ) == false )
$range .= '/32';
// $range is in IP/CIDR format eg 127.0.0.1/24
list( $range, $netmask ) = explode( '/', $range, 2 );
$range_decimal = ip2long( $range );
$ip_decimal = ip2long( $ip );
$wildcard_decimal = ( pow( 2, ( 32 - $netmask ) ) - 1);
$netmask_decimal = ~ $wildcard_decimal;
return ( ( $ip_decimal & $netmask_decimal ) == ( $range_decimal & $netmask_decimal ) );
}
function __cloudflare_check_ip( $ip ){
// @link https://www.cloudflare.com/ips/
$cf_ips = array(
'199.27.128.0/21',
'173.245.48.0/20',
'103.21.244.0/22',
'103.22.200.0/22',
'103.31.4.0/22',
'141.101.64.0/18',
'108.162.192.0/18',
'190.93.240.0/20',
'188.114.96.0/20',
'197.234.240.0/22',
'198.41.128.0/17',
'162.158.0.0/15',
'104.16.0.0/12',
'172.64.0.0/13',
'131.0.72.0/22'
);
$is_cf_ip = false;
foreach( $cf_ips as $cf_ip ) {
if( ip_in_range( $ip, $cf_ip ) ){
$is_cf_ip = true;
break;
}
}
return $is_cf_ip;
}
function __cloudflare_requests_check() {
$flag = true;
if( ! ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) || isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) || isset( $_SERVER['HTTP_CF_RAY'] ) || isset( $_SERVER['HTTP_CF_VISITOR'] ) ) )
$flag = false;
return $flag;
}
function is_cloudflare() {
$ip_cf_check = __cloudflare_check_ip( get_ip() );
$cf_request_check = __cloudflare_requests_check();
return (bool) ( $ip_cf_check && $cf_request_check );
}
$v_ip = get_real_ip();
//echo "<p>MIP: <code>{$my_ip}</code></p><br />";
//$sfip = $_SERVER['REMOTE_ADDR'];
//echo $sfip;
$myfile = fopen("$logfile", "a") or die("File lock!");
$txt = "$v_ip,$today_date,$today_year,$today_time,$browser,$uri,$v_a\n";
fwrite($myfile, $txt);
fclose($myfile);
//echo "$today";