Use network_util utilities.
Use tornado builtin to check for valid IPs.
Properly close socket.

* Since exceptions are used to trace errors, be constistent and call
  socket.connect.
Other style fixes.

* Abstract protocol in get_peer_url.