Refactor address parsing

- Extract code into separate method
- Cover with tests
- Improve hostname/IP validation