That's what the code does. It's not always possible to obtain an ip of an user. What if they have a hostmask that is unresolvable? In that case, the command isn't going to work. Not to mention trying to dns the hostmask to an IP can often take several seconds, by that time they may have already left the channel.