note 71530 deleted from function.preg-match-all by colder
| From: | colder@php.net | Date: | Mon, 16 Apr 2007 17:05:48 +0000 |
| Subject: | note 71530 deleted from function.preg-match-all by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-125477@lists.php.net to get a copy of this message | ||
Note Submitter: mrcb
----
Regarding parsing of IP addresses:
It seems to be little known that you can, in fact, specify hex and octal values in IP addresses as
well as leaving some octets out (in which case the octet value will be zero). So, for example,
0xab.0177.1 is a valid IP (V4) address and is equivalent to 171.127.0.1. So long as the resultant
combination of hex, octal and decimal is valid within
<0-255>.<0-255>.<0-255>.<0-255> (all decimal values), then, it's an IP
address and not a DNS name. Of course, use this with caution as you may end up trying access a
"network", subnet or broadcast address, if you're not careful - some devices lock up
if PINGing one of these.
You could try to create a single REGEX for parsing this, but you might be best to create a REGEX to
parse each of the (upto) four octets and then test each octet in turn - it depends what you want to
do with the value, store it / process it or simply pass it to the OS via some call (PING, open an
HTTP connection or whatever).
Don't ask me why you'd want to mix hex, octal and decimal in one address.... but it works
on most OSes I know