Merge remote-tracking branch 'origin/master' into master
This commit is contained in:
commit
4ceba04ec0
20 changed files with 395 additions and 0 deletions
3
kjg/IPv6/.gitignore
vendored
Normal file
3
kjg/IPv6/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
venv/
|
||||||
|
*.pyc
|
||||||
|
db.*
|
52
kjg/IPv6/randomnet.py
Normal file
52
kjg/IPv6/randomnet.py
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
from sys import argv
|
||||||
|
import argparse
|
||||||
|
import ipaddress
|
||||||
|
import random
|
||||||
|
#import getopt #option function
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Generating IPv6 networks")
|
||||||
|
parser.add_argument('--size', help="size")
|
||||||
|
parser.add_argument('string', nargs='+', help="network")
|
||||||
|
|
||||||
|
try:
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if argv[1] == '--size':
|
||||||
|
ipnet = argv[3]
|
||||||
|
size = 128 - int(argv[2])
|
||||||
|
else:
|
||||||
|
if len(argv) > 2 :
|
||||||
|
ipnet = argv[1]
|
||||||
|
size = 128 - int(argv[2])
|
||||||
|
else:
|
||||||
|
ipnet = argv[1]
|
||||||
|
size = 80
|
||||||
|
|
||||||
|
ip = ipnet.split('/')
|
||||||
|
ip2 = ipaddress.ip_network(ip[0]).supernet(new_prefix=int(ip[1]))
|
||||||
|
|
||||||
|
# minimum network
|
||||||
|
minNet = ipaddress.ip_network(ip[0]).supernet(new_prefix=128-size)
|
||||||
|
|
||||||
|
# seperate network
|
||||||
|
ip2first = ipaddress.IPv6Network(ip2)[0]
|
||||||
|
ip2last = ipaddress.IPv6Network(ip2)[-1]
|
||||||
|
minNetlast = ipaddress.IPv6Network(minNet)[-1]
|
||||||
|
|
||||||
|
# calculation network
|
||||||
|
maxRan = int(ip2last) - int(minNetlast) >> size
|
||||||
|
result = ipaddress.ip_address((random.randrange(0,maxRan) << size) + int(ip2first) )
|
||||||
|
resultNetwork = ipaddress.ip_network(result).supernet(new_prefix=128-size)
|
||||||
|
|
||||||
|
print(resultNetwork)
|
||||||
|
|
||||||
|
except:
|
||||||
|
info="""
|
||||||
|
wrong input
|
||||||
|
ex) --size 64 2001:db8::/40
|
||||||
|
or 2001:db8::/40 64
|
||||||
|
or 2001:db8::/40 #default size 48
|
||||||
|
"""
|
||||||
|
print(info)
|
||||||
|
|
||||||
|
|
21
kjg/IPv6/ula/manage.py
Executable file
21
kjg/IPv6/ula/manage.py
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
"""Django's command-line utility for administrative tasks."""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings')
|
||||||
|
try:
|
||||||
|
from django.core.management import execute_from_command_line
|
||||||
|
except ImportError as exc:
|
||||||
|
raise ImportError(
|
||||||
|
"Couldn't import Django. Are you sure it's installed and "
|
||||||
|
"available on your PYTHONPATH environment variable? Did you "
|
||||||
|
"forget to activate a virtual environment?"
|
||||||
|
) from exc
|
||||||
|
execute_from_command_line(sys.argv)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
0
kjg/IPv6/ula/ula/__init__.py
Normal file
0
kjg/IPv6/ula/ula/__init__.py
Normal file
16
kjg/IPv6/ula/ula/asgi.py
Normal file
16
kjg/IPv6/ula/ula/asgi.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
"""
|
||||||
|
ASGI config for ula project.
|
||||||
|
|
||||||
|
It exposes the ASGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings')
|
||||||
|
|
||||||
|
application = get_asgi_application()
|
125
kjg/IPv6/ula/ula/settings.py
Normal file
125
kjg/IPv6/ula/ula/settings.py
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
"""
|
||||||
|
Django settings for ula project.
|
||||||
|
|
||||||
|
Generated by 'django-admin startproject' using Django 3.0.8.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.0/topics/settings/
|
||||||
|
|
||||||
|
For the full list of settings and their values, see
|
||||||
|
https://docs.djangoproject.com/en/3.0/ref/settings/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
|
||||||
|
# Quick-start development settings - unsuitable for production
|
||||||
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||||
|
|
||||||
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
|
SECRET_KEY = 'fj+%jfo4xd5rb(7w!7feda03q)y4md)*)e_rjw8i_gyab!6#-h'
|
||||||
|
|
||||||
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = ["192.168.0.12",]
|
||||||
|
|
||||||
|
|
||||||
|
# Application definition
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
'django.contrib.admin',
|
||||||
|
'django.contrib.auth',
|
||||||
|
'django.contrib.contenttypes',
|
||||||
|
'django.contrib.sessions',
|
||||||
|
'django.contrib.messages',
|
||||||
|
'django.contrib.staticfiles',
|
||||||
|
'ularegistry',
|
||||||
|
]
|
||||||
|
|
||||||
|
MIDDLEWARE = [
|
||||||
|
'django.middleware.security.SecurityMiddleware',
|
||||||
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
'django.middleware.csrf.CsrfViewMiddleware',
|
||||||
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
]
|
||||||
|
|
||||||
|
ROOT_URLCONF = 'ula.urls'
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
'DIRS': [],
|
||||||
|
'APP_DIRS': True,
|
||||||
|
'OPTIONS': {
|
||||||
|
'context_processors': [
|
||||||
|
'django.template.context_processors.debug',
|
||||||
|
'django.template.context_processors.request',
|
||||||
|
'django.contrib.auth.context_processors.auth',
|
||||||
|
'django.contrib.messages.context_processors.messages',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
WSGI_APPLICATION = 'ula.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
|
'NAME': 'kjg',
|
||||||
|
'USER': 'kjg',
|
||||||
|
'PASSWORD': 'kjg#test',
|
||||||
|
'HOST': 'localhost',
|
||||||
|
'PORT': '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Password validation
|
||||||
|
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
|
||||||
|
|
||||||
|
AUTH_PASSWORD_VALIDATORS = [
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
# Internationalization
|
||||||
|
# https://docs.djangoproject.com/en/3.0/topics/i18n/
|
||||||
|
|
||||||
|
LANGUAGE_CODE = 'en-us'
|
||||||
|
|
||||||
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
USE_I18N = True
|
||||||
|
|
||||||
|
USE_L10N = True
|
||||||
|
|
||||||
|
USE_TZ = True
|
||||||
|
|
||||||
|
|
||||||
|
# Static files (CSS, JavaScript, Images)
|
||||||
|
# https://docs.djangoproject.com/en/3.0/howto/static-files/
|
||||||
|
|
||||||
|
STATIC_URL = '/static/'
|
27
kjg/IPv6/ula/ula/urls.py
Normal file
27
kjg/IPv6/ula/ula/urls.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
"""ula URL Configuration
|
||||||
|
|
||||||
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||||
|
https://docs.djangoproject.com/en/3.0/topics/http/urls/
|
||||||
|
Examples:
|
||||||
|
Function views
|
||||||
|
1. Add an import: from my_app import views
|
||||||
|
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
||||||
|
Class-based views
|
||||||
|
1. Add an import: from other_app.views import Home
|
||||||
|
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
||||||
|
Including another URLconf
|
||||||
|
1. Import the include() function: from django.urls import include, path
|
||||||
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
|
"""
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
|
||||||
|
from django.contrib import admin
|
||||||
|
from django.urls import include, path
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('ularegistry/', include('ularegistry.urls')),
|
||||||
|
path('admin/', admin.site.urls),
|
||||||
|
]
|
||||||
|
|
16
kjg/IPv6/ula/ula/wsgi.py
Normal file
16
kjg/IPv6/ula/ula/wsgi.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
"""
|
||||||
|
WSGI config for ula project.
|
||||||
|
|
||||||
|
It exposes the WSGI callable as a module-level variable named ``application``.
|
||||||
|
|
||||||
|
For more information on this file, see
|
||||||
|
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ula.settings')
|
||||||
|
|
||||||
|
application = get_wsgi_application()
|
0
kjg/IPv6/ula/ularegistry/__init__.py
Normal file
0
kjg/IPv6/ula/ularegistry/__init__.py
Normal file
3
kjg/IPv6/ula/ularegistry/admin.py
Normal file
3
kjg/IPv6/ula/ularegistry/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
kjg/IPv6/ula/ularegistry/apps.py
Normal file
5
kjg/IPv6/ula/ularegistry/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class UlaregistryConfig(AppConfig):
|
||||||
|
name = 'ularegistry'
|
13
kjg/IPv6/ula/ularegistry/checkip.py
Normal file
13
kjg/IPv6/ula/ularegistry/checkip.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
def overlapip(ip1, ip2):
|
||||||
|
|
||||||
|
test1 = ipaddress.IPv6Network(ip1).overlaps(ipaddress.IPv6Network(ip2))
|
||||||
|
|
||||||
|
if test1 :
|
||||||
|
print("overlap")
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
print("no overlap")
|
||||||
|
return 1
|
||||||
|
|
6
kjg/IPv6/ula/ularegistry/forms.py
Normal file
6
kjg/IPv6/ula/ularegistry/forms.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django import forms
|
||||||
|
from netfields import CidrAddressField, NetManager
|
||||||
|
|
||||||
|
class ip(forms.Form):
|
||||||
|
inputIP = forms.CharField()
|
||||||
|
#inputIP = CidrAddressField()
|
22
kjg/IPv6/ula/ularegistry/migrations/0001_initial.py
Normal file
22
kjg/IPv6/ula/ularegistry/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 3.0.8 on 2020-07-29 13:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import netfields.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='IPs',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('inet', netfields.fields.CidrAddressField(max_length=43)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
kjg/IPv6/ula/ularegistry/migrations/__init__.py
Normal file
0
kjg/IPv6/ula/ularegistry/migrations/__init__.py
Normal file
13
kjg/IPv6/ula/ularegistry/models.py
Normal file
13
kjg/IPv6/ula/ularegistry/models.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
from django.db import models
|
||||||
|
from netfields import CidrAddressField, NetManager
|
||||||
|
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class ips(models.Model):
|
||||||
|
inet = CidrAddressField()
|
||||||
|
objects = NetManager()
|
||||||
|
def __str__(self):
|
||||||
|
st = str(self.inet)
|
||||||
|
return st
|
||||||
|
|
||||||
|
|
14
kjg/IPv6/ula/ularegistry/templates/index.html
Normal file
14
kjg/IPv6/ula/ularegistry/templates/index.html
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form }}
|
||||||
|
<input type="submit" value="registry">
|
||||||
|
</form>
|
||||||
|
{% if ips_list %}
|
||||||
|
<ul>
|
||||||
|
{% for ips in ips_list %}
|
||||||
|
<li>{{ ips.inet }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<p>No registered IP.</p>
|
||||||
|
{% endif %}
|
3
kjg/IPv6/ula/ularegistry/tests.py
Normal file
3
kjg/IPv6/ula/ularegistry/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
8
kjg/IPv6/ula/ularegistry/urls.py
Normal file
8
kjg/IPv6/ula/ularegistry/urls.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.index, name='index'),
|
||||||
|
path('<int:ips_id>/results/', views.results, name='results'),
|
||||||
|
]
|
48
kjg/IPv6/ula/ularegistry/views.py
Normal file
48
kjg/IPv6/ula/ularegistry/views.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from django.http import HttpResponse
|
||||||
|
from .forms import ip
|
||||||
|
from ularegistry.models import ips
|
||||||
|
from django.shortcuts import redirect
|
||||||
|
from ularegistry.checkip import *
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
def index(request):
|
||||||
|
ips_list = ips.objects.values()
|
||||||
|
if request.method == "POST":
|
||||||
|
form = ip(request.POST)
|
||||||
|
print(form)
|
||||||
|
if form.is_valid():
|
||||||
|
ips_list2 = list(ips_list)
|
||||||
|
if not ips_list2:
|
||||||
|
print("test")
|
||||||
|
q = ips(inet=form.cleaned_data['inputIP'])
|
||||||
|
q.save()
|
||||||
|
|
||||||
|
overlapchk = 0
|
||||||
|
for value in ips_list2:
|
||||||
|
if overlapip(form.cleaned_data['inputIP'],value['inet']):
|
||||||
|
overlapchk = 1
|
||||||
|
else:
|
||||||
|
overlapchk = 0
|
||||||
|
break
|
||||||
|
|
||||||
|
if overlapchk:
|
||||||
|
print(overlapchk)
|
||||||
|
q = ips(inet=form.cleaned_data['inputIP'])
|
||||||
|
q.save()
|
||||||
|
|
||||||
|
return redirect('index')
|
||||||
|
|
||||||
|
else:
|
||||||
|
form = ip()
|
||||||
|
|
||||||
|
ctx = { 'form' : form,
|
||||||
|
'ips_list' : ips_list,
|
||||||
|
}
|
||||||
|
return render(request, 'index.html', ctx)
|
||||||
|
#return HttpResponse("Hello, world.")
|
||||||
|
|
||||||
|
|
||||||
|
def results(request, ips_id):
|
||||||
|
return HttpResponse(ips_id)
|
||||||
|
|
Loading…
Reference in a new issue