initial version
but working
This commit is contained in:
@@ -0,0 +1 @@
|
||||
3.13
|
||||
@@ -0,0 +1,12 @@
|
||||
# logfile Country resolver
|
||||
|
||||
## Use like
|
||||
|
||||
```bash
|
||||
cat access_crowdsec.log | stdbuf -o0 grep "/search" | grep -v "Safari/" | stdbuf -o0 /tmp/resolver | stdbuf -o0 egrep "Russia|Belarus|^SA|^AS|^AF" > block_20250227.txt
|
||||
cscli decisions delete --all; cat block_20250227.txt | cut -d"|" -f3 | perl -ne 's/(\d+)\.(\d+)\..*/$1.$2/; print ' | uniq | perl -ne 'chomp;print $_,".0.0/16\n"' | cscli decisions import -i - --format values -d48h -R toomuch_AS_SA_AF
|
||||
|
||||
```
|
||||
|
||||
## packaging
|
||||
`pyinstaller --onefile resolv.py`
|
||||
@@ -0,0 +1,7 @@
|
||||
[project]
|
||||
name = "filter-geo"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = []
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
# coding: utf-8
|
||||
|
||||
import geoip2.database
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
reader = geoip2.database.Reader("./dbip-country-lite-2025-02.mmdb")
|
||||
|
||||
try:
|
||||
with sys.stdin as file:
|
||||
for rec in file:
|
||||
try:
|
||||
parts = rec.strip().split(" ")
|
||||
ip = parts[0]
|
||||
from_country = None
|
||||
from_continent = None
|
||||
try:
|
||||
from_continent = reader.country(ip).continent.code
|
||||
from_country = reader.country(ip).country.name
|
||||
except geoip2.errors.AddressNotFoundError:
|
||||
from_country = "Unknown"
|
||||
print("{}|{}|{}".format(from_continent, from_country, "|".join(parts)))
|
||||
except:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
exit(0)
|
||||
except:
|
||||
raise
|
||||
@@ -0,0 +1,38 @@
|
||||
# -*- mode: python ; coding: utf-8 -*-
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['resolver.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
runtime_hooks=[],
|
||||
excludes=[],
|
||||
noarchive=False,
|
||||
optimize=0,
|
||||
)
|
||||
pyz = PYZ(a.pure)
|
||||
|
||||
exe = EXE(
|
||||
pyz,
|
||||
a.scripts,
|
||||
a.binaries,
|
||||
a.datas,
|
||||
[],
|
||||
name='resolver',
|
||||
debug=False,
|
||||
bootloader_ignore_signals=False,
|
||||
strip=False,
|
||||
upx=True,
|
||||
upx_exclude=[],
|
||||
runtime_tmpdir=None,
|
||||
console=True,
|
||||
disable_windowed_traceback=False,
|
||||
argv_emulation=False,
|
||||
target_arch=None,
|
||||
codesign_identity=None,
|
||||
entitlements_file=None,
|
||||
)
|
||||
Reference in New Issue
Block a user