when I do this
ip = request.env["REMOTE_ADDR"]
I get the client’s IP address it it. But what if I want to validate whether the value in the variable is really an IP?
How do I do that?
Please help.
Thanks in advance. And sorry if this question is repeated, I didn’t take the effort of finding it…
EDIT
What about IPv6 IP’s??
Why not let a library validate it for you? You shouldn’t introduce complex regular expressions that are impossible to maintain.
Then, in your application
You can also use Ruby’s built-in
IPAddrclass, but it doesn’t lend itself very well for validation.Of course, if the IP address is supplied to you by the application server or framework, there is no reason to validate at all. Simply use the information that is given to you, and handle any exceptions gracefully.