I don't really like doing a network lookup for this, domain name changes during execution of the program are possible.

CNode already stores the name through which we connected to a peer (CNode::addrName) and the IP address as a fallback (CNode::addr); we should be doing lookups based on this.