I want to make a simple IP check for values between 0-255 without using
expressions, so I created the code below: (But c and d always gives
first if -statement. Does not not split handle 4 integer split, or have
I done it incorrectly?)
(a,b,c,d) = ARGV[0].split(’.’)
if (a < ‘0’ || a > ‘255’ || b < ‘0’ || b > ‘255’ || c < ‘0’ || c > ‘255’
|| d < ‘0’ || d > ‘255’)
puts " IP IS WRONG"
else
puts “IP is good”
end
I want to make a simple IP check for values between 0-255 without using
expressions, so I created the code below: (But c and d always gives
first if -statement. Does not not split handle 4 integer split, or have
I done it incorrectly?)
(a,b,c,d) = ARGV[0].split(’.’)
if (a < ‘0’ || a > ‘255’ || b < ‘0’ || b > ‘255’ || c < ‘0’ || c > ‘255’
|| d < ‘0’ || d > ‘255’)
puts " IP IS WRONG"
else
puts “IP is good”
end
Forexample try with IP: 128.141.58.42 (Which is correct!!)
Forexample try with IP: 128.141.58.42 (Which is correct!!)
You are comparing as strings, and in the lexicographical ordering ‘58’
is > ‘255’ since ‘5’ > ‘2’.
Convert to integers before comparing and you should be ok.
Forexample try with IP: 128.141.58.42 (Which is correct!!)
You are comparing as strings, and in the lexicographical ordering ‘58’
is > ‘255’ since ‘5’ > ‘2’.
Convert to integers before comparing and you should be ok.
Fred
Fred,
thank you very much for that enlightning information, certainly found my
mistake!