Hmm. What I would probably do there is leave UIDs on as long as the user’s query isn’t a complete, valid IP address and turn them off as soon as it is.
So it first works as a query to filter the history using Alfred’s sorting, but if the query is a complete IP address, that’s shown as the top result (“do X with xx.xx.xx.xx”) while the history is shown below sorted by length of prefix match.
So if you enter “10.0.0.1”, “10.0.0.10” should be at least near the top where you can action it with CMD+<NUM>.
Not so good if you’ll have whole subnets in the history, I suppose.