[PATCH nftables geoip 0/1] contrib: geoip: add geoip python script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds a python script which generates .nft files that
contains mappings between the IP address and its geolocation.

It requires two csv files:

1) location database, this is stored in the location.csv file. This
   is currently a modified version of

https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.csv

   You can specify the location database path via the --file-location

2) geoip database. Provided by db-ip.com. This csv file can be downloaded
   with the --download option.
   You can also specify the file through --file-address

This script generates the following output files:

    geoip-def-*.nft: contains definitions for countries of a continent to its
    2-digit iso-3166 code

    geoip-ipv{4/6}.nft: contains maps for ip blocks mapped to the 2-digit
    iso-3166 value of the country.


Output directory can be specified with '-o' option. It must be an
existing directory.

Example, a counter of input packets from Spanish addresses, (there is a
folder named "test-geoip" in the current directory):

./nft_geoip.py -o test-geoip/ --file-location location.csv --download

Then you can include the country definitions "geoip-def-all.nft" and geoip
"geoip-ipv{4,6}.nft".

table filter {
    include "./geoip-def-all.nft"
    include "./geoip-ipv4.nft"
    include "./geoip-ipv6.nft"

    chain input {
	    type filter hook input priority filter; policy accept;
	    meta mark set ip saddr map @geoip4
	    meta mark $ES counter
    }

}

Jose M. Guisado Gomez (1):
  contrib: geoip: add geoip python script

 contrib/geoip/location.csv | 251 ++++++++++++++++++++++++++++++
 contrib/geoip/nft_geoip.py | 310 +++++++++++++++++++++++++++++++++++++
 2 files changed, 561 insertions(+)
 create mode 100644 contrib/geoip/location.csv
 create mode 100755 contrib/geoip/nft_geoip.py

-- 
2.23.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux