IP-based access guard for Python apps
Project description
knw-license
IP 기반으로 Python 앱의 실행 환경을 제한하는 라이브러리입니다.
설치
pip install knw-license
사용법
함수형
import knw_license
# 공인 IP 검사 (기본)
knw_license.check()
# 내부 IP 검사
knw_license.check(mode="local")
# 공인 + 내부 중 하나라도 허용 목록에 있으면 통과
knw_license.check(mode="both")
데코레이터형
from knw_license import guard
@guard
def main():
print("허용된 환경에서 실행 중")
@guard(mode="both")
def main():
print("허용된 환경에서 실행 중")
예외 처리
from knw_license.exceptions import AccessDeniedError, IPResolutionError
try:
knw_license.check()
except AccessDeniedError as e:
print(f"차단된 IP: {e.ip}")
print(f"검사 모드: {e.mode}")
except IPResolutionError as e:
print(f"IP 조회 실패: {e}")
IP 목록 관리
knw_license/_allowlist.py 의 ALLOWED_CIDRS 리스트를 수정합니다.
ALLOWED_CIDRS: list[str] = [
"203.0.113.5/32", # 단일 공인 IP
"192.168.1.0/24", # 사무실 내부망
"10.0.0.0/8", # VPN 대역
]
변경 후 버전을 올려 재배포합니다.
# pyproject.toml 버전 수정 후
python -m build
twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
knw_license-0.1.1.tar.gz
(5.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file knw_license-0.1.1.tar.gz.
File metadata
- Download URL: knw_license-0.1.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f72303c95a77063805c26bbf41c0cb29f0ec44656c750f1cf9fcb0406a4c6a22
|
|
| MD5 |
bc603a711f0aacbda6c72022b1d3872f
|
|
| BLAKE2b-256 |
f2c62a918042d18090d9cfbda13113caa2ffa5d53acfc9bb059e85724fdda7a5
|
File details
Details for the file knw_license-0.1.1-py3-none-any.whl.
File metadata
- Download URL: knw_license-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9f8c6b20ed6fef157f9b094dacc6cf2013c2cd5aea5e827322d4575dabb04d9
|
|
| MD5 |
18b6074ccd42e1e3941108c4fdb9bc78
|
|
| BLAKE2b-256 |
53c5428275c4363cc98f19802021035cf33cf106f2dc349d2e40c7d7234dc5a8
|