change sed pattern to only match when GetExternalIPAaddress succeeds and output nothing if it fails
$ upnpc -s | grep ExternalIPAddress | sed 's/[^0-9\.]//g'
.3
$ upnpc -s | grep ExternalIPAddress
GetExternalIPAddress failed. (errorcode=-3)
$ upnpc -s | sed -n -e 's/^ExternalIPAddress = \([0-9.]*\)$/\1/p'
$