File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,17 @@ public function inNetworks($networks)
155
155
*/
156
156
abstract public function inNetwork ($ network );
157
157
158
+ /**
159
+ * Checks if this IP is a network.
160
+ * This generally means hostmask is < 32 or < 128
161
+ *
162
+ * @return bool
163
+ */
164
+ public function isNetwork ()
165
+ {
166
+ return $ this ->cidr < $ this ->host_bits ;
167
+ }
168
+
158
169
/**
159
170
* Check if this IP is in the reserved range.
160
171
* @return bool
Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ public function testNetworkParse()
82
82
$ this ->assertEquals ('::1 ' , IP ::parse ('::1/128 ' ));
83
83
}
84
84
85
+ public function testIsNetwork ()
86
+ {
87
+ $ this ->assertFalse (IP ::parse ('192.168.3.0 ' )->isNetwork ());
88
+ $ this ->assertFalse (IP ::parse ('192.168.3.0/32 ' )->isNetwork ());
89
+ $ this ->assertTrue (IP ::parse ('192.168.3.0/24 ' )->isNetwork ());
90
+ $ this ->assertFalse (IPv6::parse ('2001:db8:85a3::8a2e:370:7334 ' )->isNetwork ());
91
+ $ this ->assertFalse (IPv6::parse ('2001:db8:85a3::8a2e:370:7334/128 ' )->isNetwork ());
92
+ $ this ->assertTrue (IPv6::parse ('2001:db8:85a3::8a2e:370:7334/64 ' )->isNetwork ());
93
+ }
94
+
85
95
/**
86
96
* @expectedException \LibreNMS\Exceptions\InvalidIpException
87
97
*/
You can’t perform that action at this time.
0 commit comments