jonhadfield / python-hosts

a hosts file manager library written in python
MIT License
125 stars 33 forks source link

Feature request: A way to get all matching hostentries. #33

Closed Lilja closed 3 years ago

Lilja commented 4 years ago

I would like a method in the hosts-module, a way to get a hostentry based on a name.

This is how I'm solving it right now:

    api = next(iter([
        host
        for host in hosts.entries
        if host.names and N_API_URL in host.names
    ]), None)
jonhadfield commented 3 years ago

I've added this functionality in version 1.0.1.

Example usage:

hosts.find_all_matching(name="ischeeseavegetable.com")  
hosts.find_all_matching(address="87.81.255.195")  
hosts.find_all_matching(address="87.81.255.195", name="ischeeseavegetable.com")  # returning where both match