Shouldn't the IP address "169.254.169.254" be a private IP?

Hey everyone,

I have a script that checks whether an IP is public or private. Here are the important bits from crystal i

Crystal interpreter 1.7.2 (2023-01-23).
EXPERIMENTAL SOFTWARE: if you find a bug, please consider opening an issue in
https://github.com/crystal-lang/crystal/issues/new/
icr:1> require "socket"
 => nil
icr:2> ip_address = Socket::IPAddress.new("169.254.169.254", 0)
 => Socket::IPAddress(169.254.169.254:0)
icr:3> ip_address.private?
 => false
icr:4> ip_address.loopback?
 => false
icr:5> ip_address.unspecified?
 => false
icr:6>

My question is - shouldn’t the IP 169.254.169.254 come up as a Private IP ?

If not - what’s the best way to check if this IP is not a public IP ?

Thanks!

1 Like

Looking at the code, it seems we’re currently only handling the ranges defined in RFC1918 and are missing those defined in RFC6890 as Reserved-by-Protocol, specifically:

IPV4:

  • 0.0.0.0/8
  • 127.0.0.0/8
  • 169.254.0.0/16 (which is the range your IP is in)
  • 240.0.0.0/4

IPV6:

  • ::1/128
  • ::/128
  • ::ffff:0:0/96
  • fe80::/10

Can you file an issue for this?

3 Likes

Hi @Blacksmoke16 , I appreciate the quick response!

Sure thing, I’ll report back once I’ve filed the issue.

Hi @Blacksmoke16, I have filed this an issue here: the IP 169.254.169.254 is not recognized as as a Private IP · Issue #13198 · crystal-lang/crystal · GitHub

Thanks again!