Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F36150450
ranges2geo.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
ranges2geo.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Convert CIDR ranges into map for ngx_http_geo_module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# License: BSD-2-Clause
# -------------------------------------------------------------
import
sys
# -------------------------------------------------------------
# Formatter for ngx_http_geo_module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
get_geo_entry
(
line
):
line
=
line
.
strip
()
if
line
==
""
:
return
line
elif
line
.
startswith
(
"#"
):
return
" "
+
line
return
f
" {line} 1;"
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
run
(
ranges_path
):
print
(
"geo $range {"
)
print
(
" default 0;"
)
print
()
with
open
(
ranges_path
)
as
fd
:
for
line
in
fd
:
print
(
get_geo_entry
(
line
))
print
(
"}"
)
if
__name__
==
"__main__"
:
argc
=
len
(
sys
.
argv
)
if
argc
<
2
:
print
(
f
"Usage: {sys.argv[0]} <ranges file>"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
run
(
sys
.
argv
[
1
])
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Jul 16, 15:05 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3914174
Default Alt Text
ranges2geo.py (1 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment