Re-wrote to write over entire line (not all ips are the same length).
Added error handling and the ability to pass dns alias as second argument.