1 Reply Latest reply: Mar 25, 2014 3:53 PM by Christopher White RSS

How do I use the ip address rather than the name for response map

George Berkeley

Since I have multiple ip's at one site, I need to put the same site name in the locations file many times.

 

NEWYORK 1.0.0.0/24

NEWYORK 2.0.0.0/24

NEWYORK 10.0.0.0/23

NEWYORK 25.0.0.0/16

PARIS 50.0.0.0/16

PARIS 100.0.0.0/8

GREECE 101.1.1.0/24

MADRID 101.1.2.0/24

 

 

The maps.py uses the name rather than the ip address. I have tried changing the following line from name to address, but the map rendered empty. So I believe I missed something.

 

geo = Location.objects.get(ADDRESS=key)

 

Suggestions?

 

Thanks

  • Re: How do I use the ip address rather than the name for response map
    Christopher White

    Hey George,

     

    The Location map currently only allows lookup up by name to yield the latitude and longitude.  There is a package called PySubnetTree that does efficient lookup of IP addresses against subnets like this.  We are working on a big new release of the code and I'll include part of this package as a sample that will show how to do this kind of lookup.

     

    If you want to take a crack at some of it now, here's the basics of using PySubnetTree:

     

    First, you need to install it.  The easiest is via 'pip':

    $ pip install -e git+git://git.bro.org/pysubnettree.git#egg=pysubnettree

     

    If you have it installed in a virtual environment, be sure to run this command within the venv.

     

    Once installed, here's a python snippet that shows how to add entries and lookup entries:

     

    >>> from SubnetTree import SubnetTree
    >>> tree = SubnetTree()
    >>> tree['10.0.0.0/8'] = 'Massachusetts'
    >>> tree['10.1.0.0/16'] = 'Boston'
    >>> tree['10.2.0.0/16'] = 'Cambridge'
    >>> print tree['10.1.2.3']
    Boston
    >>> print tree['10.2.3.4']
    Cambridge
    >>> print tree['10.3.4.5']
    Massachusetts
    

     

    We'll make a note of integrating this into the Location lookup an map code.

     

    Thanks.