diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2be639f --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..54ec6ab --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2024, acidvegas + +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. diff --git a/pylcg/__init__.py b/pylcg/__init__.py new file mode 100644 index 0000000..99eee9c --- /dev/null +++ b/pylcg/__init__.py @@ -0,0 +1,5 @@ +from .core import LCG, IPRange, ip_stream + +__version__ = "1.0.0" +__author__ = "acidvegas" +__all__ = ["LCG", "IPRange", "ip_stream"] \ No newline at end of file diff --git a/pylcg/cli.py b/pylcg/cli.py new file mode 100644 index 0000000..81e29c9 --- /dev/null +++ b/pylcg/cli.py @@ -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() \ No newline at end of file diff --git a/pylcg/core.py b/pylcg/core.py new file mode 100644 index 0000000..66228a2 --- /dev/null +++ b/pylcg/core.py @@ -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) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..16bd754 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..06b14aa --- /dev/null +++ b/setup.py @@ -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', + ], + }, +) \ No newline at end of file