def ips_from_network(self, network):
        #FIXME: a /24 should do two /23 searches, not 1/16
        net = serialize_ip(str(network.net()))
        strip = network.prefixlen()/8
        prefix = net[:strip]

        ips = [i.term for i in self.database.allterms(prefix)]
        return ips
Beispiel #2
0
    def ips_from_network(self, network):
        #FIXME: a /24 should do two /23 searches, not 1/16
        net = serialize_ip(str(network.net()))
        strip = network.prefixlen() / 8
        prefix = net[:strip]

        ips = [i.term for i in self.database.allterms(prefix)]
        return ips
Beispiel #3
0
def test_netmask_expand():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("1.2.3.0/24")
    print expanded
    assert expanded == [
        serialize_ip(ip) for ip in ["1.2.3.4", "1.2.3.5", "1.2.3.6"]
    ]
    def expand_netmask(self, netmask):
        """Expand netmask based on the terms in the database.
           Doesn't bother using the database for tiny networks"""
        network = IPy.IP(netmask)
        if network.len() < 32:
            return [serialize_ip(str(ip)) for ip in network]
        ips = self.ips_from_network(network)

        if network.prefixlen() % 8 !=0:
            ips = [ip for ip in ips if IPy.IP(deserialize_ip(ip)) in network]
        return ips
 def search_ips(self, ips):
     words = []
     for ip in ips:
         if '/' in ip:
             net = self.expand_netmask(ip)
             #FIXME: raise exception?
             if len(net) < 300:
                 words.extend(net)
         else :
             words.append(serialize_ip(ip))
     return self.do_search(words)
Beispiel #6
0
    def expand_netmask(self, netmask):
        """Expand netmask based on the terms in the database.
           Doesn't bother using the database for tiny networks"""
        network = IPy.IP(netmask)
        if network.len() < 32:
            return [serialize_ip(str(ip)) for ip in network]
        ips = self.ips_from_network(network)

        if network.prefixlen() % 8 != 0:
            ips = [ip for ip in ips if IPy.IP(deserialize_ip(ip)) in network]
        return ips
Beispiel #7
0
 def search_ips(self, ips):
     words = []
     for ip in ips:
         if '/' in ip:
             net = self.expand_netmask(ip)
             #FIXME: raise exception?
             if len(net) < 300:
                 words.extend(net)
         else:
             words.append(serialize_ip(ip))
     return self.do_search(words)
def test_netmask_expand_ipv6():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("2001:4860::/32")
    print expanded
    assert expanded == [serialize_ip("2001:4860:800f::68")]
def test_netmask_expand_23():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("3.3.2.0/23")
    print expanded
    assert expanded == [serialize_ip("3.3.3.99")]
def test_netmask_expand():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("1.2.3.0/24")
    print expanded
    assert expanded == [serialize_ip(ip) for ip in ["1.2.3.4", "1.2.3.5", "1.2.3.6"]]
Beispiel #11
0
def serde_case(ip):
    other = deserialize_ip(serialize_ip(ip))
    eq_(ip, other)
def serde_case(ip):
    other = deserialize_ip(serialize_ip(ip))
    eq_(ip, other)
Beispiel #13
0
def test_netmask_expand_ipv6():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("2001:4860::/32")
    print expanded
    assert expanded == [serialize_ip("2001:4860:800f::68")]
Beispiel #14
0
def test_netmask_expand_23():
    s = searcher.BaseSearcher('tests/2011-04-15.db')

    expanded = s.expand_netmask("3.3.2.0/23")
    print expanded
    assert expanded == [serialize_ip("3.3.3.99")]