File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,37 @@ public static function isValidv6($ip)
73
73
return (bool )filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 );
74
74
}
75
75
76
+ /**
77
+ * Checks if an IP is local
78
+ *
79
+ * @param string $ip IP
80
+ * @return boolean true if the IP is local, otherwise false
81
+ */
82
+ public static function isLocal ($ ip )
83
+ {
84
+ if (self ::isValidv4 ($ ip )) {
85
+ return self ::match ($ ip , '10.*.*.* ' ) ||
86
+ self ::match ($ ip , '127.*.*.* ' ) ||
87
+ self ::match ($ ip , '192.168.*.* ' ) ||
88
+ self ::match ($ ip , '169.254.*.* ' ) ||
89
+ self ::match ($ ip , '172.16.*.* ' ) ||
90
+ self ::match ($ ip , '224.*.*.* ' );
91
+ }
92
+
93
+ return false ;
94
+ }
95
+
96
+ /**
97
+ * Checks if an IP is remot
98
+ *
99
+ * @param string $ip IP
100
+ * @return boolean true if the IP is remote, otherwise false
101
+ */
102
+ public static function isRemote ($ ip )
103
+ {
104
+ return !self ::isLocal ($ ip );
105
+ }
106
+
76
107
/**
77
108
* Checks if an IP is part of an IP range.
78
109
*
Original file line number Diff line number Diff line change @@ -190,4 +190,22 @@ public function test9()
190
190
$ this ->assertEquals ('fe80::202:b3ff:fe1e:8329 ' , $ dec );
191
191
}
192
192
193
+ /**
194
+ * @test
195
+ */
196
+ public function testLocal ()
197
+ {
198
+ $ status = Ip::isLocal ('192.168.5.5 ' );
199
+ $ this ->assertTrue ($ status );
200
+ }
201
+
202
+ /**
203
+ * @test
204
+ */
205
+ public function testRemote ()
206
+ {
207
+ $ status = Ip::isRemote ('8.8.8.8 ' );
208
+ $ this ->assertTrue ($ status );
209
+ }
210
+
193
211
}
You can’t perform that action at this time.
0 commit comments