Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function inet_private($addrString)
- {
- $addr = inet_pton($addrString);
- if(strlen($addr) !== 4)
- throw new Exception('Only valid IPv4 addresses are currently supported.');
- $ta = unpack('n*', $addr);
- $addr = reset($ta);
- return $addr === 49320 // 192.168.0.0/16
- || ($addr &~ 15) === 44048 // 172.16.0.0/12
- || ($addr &~ 255) === 32512 // 127.0.0.0/8
- || ($addr &~ 255) === 2560; // 10.0.0.0/8
- }
Advertisement
Add Comment
Please, Sign In to add comment