Jul. 19th, 2012

rmd: (Default)
So, I'm trying to write some stuff in PHP, and I've run into a thing I can't seem to figure out how to do. I want to take two IP addresses (in dotted decimal format) and a CIDR mask, and see if IP-1 is contained within IP-2/mask.

I've been poking around to see if this is an obviously solved problem - and I would think it must be, because it's not an unusual problem, but I can't seem to find it. And trying to script this myself is causing me to go cross-eyed trying to figure out how to do binary math without the ability to cast a variable as a binary. (Really, PHP? Really?)

I suppose one solution is to go get a real language, or maybe wait until phpv6. But, still, for something that's allegedly optimized for web-based stuff, I'm really shocked there doesn't seem to be much in the way of built-in IP-wrangling stuff besides, say, "ip2long" which will take a dotted decimal format IPv4 addr and turn it into a long integer.

Profile

rmd: (Default)
rmd

June 2025

S M T W T F S
1234567
89 1011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 11th, 2025 07:32 pm
Powered by Dreamwidth Studios