If the machine has a public IPv4 address, there is no need for UPnP
Better checking of a valid external IPv4 address
Try to get a valid external IPv6 address