@Juan Since you're concerned about the performance, which is valid, I've also removed all the string-conversions. Important question: Is 1.0.0.127 a valid public IP-Adress? If yes, I'd have to furtherly change the code, adding some htonl, ntohl, or similar.
greetings, David