Not going to do any explaining, but here are some functions to check out.
getmxrr(sting host, array mxhost, array weight)
gethostbyaddr(string ip_address)
gethostbyname(string hostname)
First one is probably what you are looking for, but thought I would include the other two. L8r d00d.