Ruby resolv library how to exclude non-IPv4 addresses -
I want to use the library to resolve hostnames with 'localhost' but this non-IPv4 address is also listed Does. I want to find the first IPv4 address. Looked at the library, but there was no way to do this. Does anyone know a way to do this, or should we go for other gems such as NET: DNS or DNSRUB?
If I think that you are correct Resolv :: IPv4 :: Regexp And you can use the
Resolv :: IPv6 :: Regexp example:
= & gt; Expected 'resolv' = & gt; P Resolv.getaddress "www.ruby-lang.org" # & gt; "23.23.144.121" = & gt; Ip = "23.23.144.121" = & gt; IP = ~ Rise: IPv4 :: Regex # & gt; 0 = & gt; Ip = ~ Resolv :: IPv6 :: Regex # & gt; Zero = & gt; Case ip = & gt; When Resolv :: IPv4 :: Regex = & gt; Say "This is a valid IPv4 address." = & Gt; When Resolv :: IPv6 :: Regex = & gt; Say "This is a valid IPv6 address." = & Gt; Else = & gt; "This is not a valid IP address." = & Gt; End # & gt; This is a valid IPv4 address.
Comments
Post a Comment