Module: Cybertrain::Net::Address
- Defined in:
- cybertrain/net/address.rb
Class Method Summary collapse
-
.blocked_reason(ip) ⇒ String
The reason an outbound request must not reach
ip, or “” when it is a public address. -
.public?(ip) ⇒ Boolean
True when
ipis a public address (blocked_reason is “”).
Class Method Details
.blocked_reason(ip) ⇒ String
The reason an outbound request must not reach ip, or “” when it is
a public address. ip is what getaddrinfo answers: dotted IPv4
(“10.0.0.5”) or IPv6 text (“fe80::1%eth0”, “::ffff:127.0.0.1”). A
String that parses as neither is refused (“not an IP address”).
28 29 30 31 32 33 34 35 36 37 |
# File 'cybertrain/net/address.rb', line 28 def self.blocked_reason(ip) text = ip.to_s # NOTES rule 62 v4 = Address.parse_ipv4(text) return Address.ipv4_reason(v4) if v4.size == 4 v6 = Address.parse_ipv6(text) return Address.ipv6_reason(v6) if v6.size == 16 "not an IP address" end |
.public?(ip) ⇒ Boolean
True when ip is a public address (blocked_reason is “”).
43 44 45 |
# File 'cybertrain/net/address.rb', line 43 def self.public?(ip) Address.blocked_reason(ip).empty? end |