in reply to Regular Expression to Match IP Address

Did you know that 10.1, 10.0.1, 10.0.0.1, and 167772161 are all valid IPv4 addresses, all referring to the same machine? You may want to check your assumptions and make sure that you have documented which IPv4 address formats you will support.
  • Comment on Re: Regular Expression to Match IP Address

Replies are listed 'Best First'.
Re^2: Regular Expression to Match IP Address
by TedPride (Priest) on Oct 03, 2004 at 21:12 UTC
      I don't see anything there about it, and even if you're correct...

      It looks like wikipedia is not an authoratative source on IP addresses ;) I believe IPv4 is described in detail in RFC 791 (would someone please correct this if I gave the wrong rfc please!) IPv6 is detailed in RFC 2460.

      IPv4 addresses are just 32 bit numbers that are displayed as a dotted quad for our convenience. It is much easier (at least to my eye) to look at and understand "10.0.0.1 netmask 255.255.255.0" than "167772161 netmask 4294967040", even though they are equivalent. Look at the following examples if you don't believe this.

      perl -e 'print "true!" if 10 * 256**3 + 0 * 256**2 + 0 * 256 + 1 == 16 +7772161' # prints true!

      or try this:

      $ ping 167772161 PING 167772161 (10.0.0.1): 56 data bytes ^C --- 167772161 ping statistics --- 2 packets transmitted, 0 packets received, 100% packet loss
      A reply falls below the community's threshold of quality. You may see it by logging in.