X-Git-Url: http://git.pk910.de/?p=PHP-P10.git;a=blobdiff_plain;f=Uplink%2FIPAddr.class.php;fp=Uplink%2FIPAddr.class.php;h=2370cf66e48fab506177595eec9a74ad9edd3611;hp=1eddcbed0aa7f872ff688d122121426430ffd534;hb=ba724f8fe4ffd71406db9faa3612ef6fc5da612f;hpb=f37602484b52f7c99bafdf506b83349adbc0763c diff --git a/Uplink/IPAddr.class.php b/Uplink/IPAddr.class.php index 1eddcbe..2370cf6 100644 --- a/Uplink/IPAddr.class.php +++ b/Uplink/IPAddr.class.php @@ -96,6 +96,34 @@ class IPAddr { public function isIPv6() { return $this->addr_is_ipv6; } + + public function isLocalAddress() { + /* checks if address is out of: + * 127.0.0.1/32 + * 10.0.0.0/8 + * 192.168.0.0/16 + * 172.16.0.0/12 + * ::1/128 + * fc00::/7 + */ + if($this->addr_is_ipv6) { + if( + (($this->ip6[0] & 0xFE00) == 0xFC00) || /* fc00::/7 */ + ($this->ip6[0] == 0 && $this->ip6[1] == 0 && $this->ip6[2] == 0 && $this->ip6[3] == 0 && + $this->ip6[4] == 0 && $this->ip6[5] == 0 && $this->ip6[6] == 0 && $this->ip6[7] == 1) + ) + return true; + } else { + if( + (($this->ip6[6] & 0xFFFF) == 0x7F00 && ($this->ip6[7] & 0xFFFF) == 0x0001) || /* 127.0.0.1/32 */ + (($this->ip6[6] & 0xFF00) == 0x0A00) || /* 10.0.0.0/8 */ + (($this->ip6[6] & 0xFFF0) == 0xAC10) || /* 172.16.0.0/12 */ + (($this->ip6[6] & 0xFFFF) == 0xC0A8) /* 192.168.0.0/16 */ + ) + return true; + } + return false; + } public function getAddress() { if($this->isIPv6()) {