Well, I would restructure that section.
Check to see if $_SERVER['REMOTE_ADDR'] is one of your IP's, or an IP you don't want to count. If so, [man]exit[/man] the script (or [man]return[/man] a value for the function/loop so it stops).
If not, go ahead and get the host using gethostbyaddr() and continuing on with your logging script.