packaged
This commit is contained in:
parent
9b0a627b03
commit
5fe2590e38
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
# Python
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
*.so
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# Virtual Environment
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env/
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
15
LICENSE
Normal file
15
LICENSE
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2024, acidvegas <acid.vegas@acid.vegas>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
5
pylcg/__init__.py
Normal file
5
pylcg/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .core import LCG, IPRange, ip_stream
|
||||||
|
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
__author__ = "acidvegas"
|
||||||
|
__all__ = ["LCG", "IPRange", "ip_stream"]
|
26
pylcg/cli.py
Normal file
26
pylcg/cli.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import argparse
|
||||||
|
from .core import ip_stream
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description='Ultra-fast random IP address generator with optional sharding')
|
||||||
|
parser.add_argument('cidr', help='Target IP range in CIDR format')
|
||||||
|
parser.add_argument('--shard-num', type=int, default=1, help='Shard number (1-based)')
|
||||||
|
parser.add_argument('--total-shards', type=int, default=1, help='Total number of shards (default: 1, no sharding)')
|
||||||
|
parser.add_argument('--seed', type=int, default=0, help='Random seed for LCG')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.total_shards < 1:
|
||||||
|
raise ValueError('Total shards must be at least 1')
|
||||||
|
|
||||||
|
if args.shard_num > args.total_shards:
|
||||||
|
raise ValueError('Shard number must be less than or equal to total shards')
|
||||||
|
|
||||||
|
if args.shard_num < 1:
|
||||||
|
raise ValueError('Shard number must be at least 1')
|
||||||
|
|
||||||
|
for ip in ip_stream(args.cidr, args.shard_num, args.total_shards, args.seed):
|
||||||
|
print(ip)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
19
pylcg/core.py
Normal file
19
pylcg/core.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import ipaddress
|
||||||
|
import random
|
||||||
|
|
||||||
|
class LCG:
|
||||||
|
'''Linear Congruential Generator for deterministic random number generation'''
|
||||||
|
|
||||||
|
def __init__(self, seed: int, m: int = 2**32):
|
||||||
|
self.m = m
|
||||||
|
self.a = 1664525
|
||||||
|
self.c = 1013904223
|
||||||
|
self.current = seed
|
||||||
|
|
||||||
|
def next(self) -> int:
|
||||||
|
'''Generate next random number'''
|
||||||
|
self.current = (self.a * self.current + self.c) % self.m
|
||||||
|
return self.current
|
||||||
|
|
||||||
|
# Rest of the code from pylcg.py goes here...
|
||||||
|
# (IPRange class and ip_stream function)
|
3
pyproject.toml
Normal file
3
pyproject.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=42", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
43
setup.py
Normal file
43
setup.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
with open("README.md", "r", encoding="utf-8") as fh:
|
||||||
|
long_description = fh.read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name="pylcg",
|
||||||
|
version="1.0.0",
|
||||||
|
author="acidvegas",
|
||||||
|
author_email="acid.vegas@acid.vegas",
|
||||||
|
description="Linear Congruential Generator for IP Sharding",
|
||||||
|
long_description=long_description,
|
||||||
|
long_description_content_type="text/markdown",
|
||||||
|
url="https://github.com/acidvegas/pylcg",
|
||||||
|
project_urls={
|
||||||
|
"Bug Tracker": "https://github.com/acidvegas/pylcg/issues",
|
||||||
|
"Documentation": "https://github.com/acidvegas/pylcg#readme",
|
||||||
|
"Source Code": "https://github.com/acidvegas/pylcg",
|
||||||
|
},
|
||||||
|
classifiers=[
|
||||||
|
"Development Status :: 5 - Production/Stable",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: ISC License (ISCL)",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python :: 3",
|
||||||
|
"Programming Language :: Python :: 3.6",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Topic :: Internet",
|
||||||
|
"Topic :: Security",
|
||||||
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
|
],
|
||||||
|
packages=find_packages(),
|
||||||
|
python_requires=">=3.6",
|
||||||
|
entry_points={
|
||||||
|
'console_scripts': [
|
||||||
|
'pylcg=pylcg.cli:main',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user