title: How can I find which interface a connection to a given host will be routed through?
body: <p>My script needs configure SNMP trap destinations for a number of hosts which exist different networks. It is therefor important that the trap destination address is of the interface that is accessible to the remote node.</p>
  
  <p>I don't really want to parse the linux kernel routing table as it's likely to be fragile and break easily. Is there anyway to interrogate the kernel and get it to tell me which way a packet would be routed.</p>
  
  <p>Ideally there would be a python solution for this. I've been looking at the python bindings for libdnet but that only seems to be able to return the default gateway for the address 0.0.0.0.</p>