Function is significantly quicker and uses 1 SQL query per IP rather than 1 query per port.
Tests aren't working as well as I had hoped, so a lot are commented out while I wait to hear back on this bug causing them to fail.
Needs tests written, uses new validation on model.