I don't understand your ip_to_hex() function. If you want to convert a string with the ip in this format "70.42.23.121" then your function should take a string and not an integer.