Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F448904
ipv6_validator.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Apr 24, 11:30 AM
Size
622 B
Mime Type
text/x-ruby
Expires
Sat, Apr 26, 11:30 AM (1 d, 13 h)
Engine
blob
Format
Raw Data
Handle
212563
Attached To
rWEBDNS WebDNS (edet4)
ipv6_validator.rb
View Options
require
'ipaddr'
require
'socket'
class
Ipv6Validator
<
ActiveModel
::
EachValidator
# Returns true if addr is valid IPv6 address.
def
valid_v6?
(
addr
)
return
false
if
addr
[
'/'
]
# IPAddr accepts addr/mask format
return
false
if
addr
[
'['
]
return
false
if
addr
[
']'
]
IPAddr
.
new
(
addr
,
Socket
::
AF_INET6
)
true
rescue
IPAddr
::
AddressFamilyError
,
IPAddr
::
InvalidAddressError
false
end
# Add an attribute error if this is not a valid IPv4 address.
def
validate_each
(
record
,
attribute
,
value
)
return
if
valid_v6?
(
value
)
record
.
errors
[
attribute
]
<<
'is not a valid IPv6 address'
end
end
Event Timeline
Log In to Comment