iputil.py: fix an error handling bug. refs #1381

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
iputil.py: add tests for recent changes. refs #1381, #1988, #982, #1064, #1536, #1935, #898, #1707, #1918

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>