Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@
- [Login](#login)
- [Register](#register)
- [Refresh token](#refresh-token)
- [Users](#users)
- [Get all users](#get-all-users)
- [Get user by username](#get-user-by-username)
- [Get own user](#get-own-user)
- [Update user](#update-user)
- [Update own user](#update-own-user)
- [Update user password](#update-user-password)
- [Delete user](#delete-user)
- [IPv4](#ipv4)
- [Get IPv4 class](#get-ipv4-class)
- [Convert dec to bin](#convert-dec-to-bin)
- [Convert dec to hex](#convert-dec-to-hex)
- [Convert hex to dec](#convert-hex-to-dec)
- [Convert bin to dec](#convert-bin-to-dec)
- [Get CIDR notation](#get-cidr-notation)
- [Get mask](#get-mask)
- [Get VLSM](#get-vlsm)
- [IPv6](#ipv6)
- [Simplify IPv6](#simplify-ipv6)
- [Extend IPv6](#extend-ipv6)
Expand Down Expand Up @@ -71,6 +81,8 @@
}
```

### Users

#### Get all users

| Method | URL | Description | Need token | Roles |
Expand Down Expand Up @@ -139,6 +151,56 @@
| ------ | ----------------- | ----------- | ---------- | ----- |
| DELETE | /users/{username} | Delete user | True | Admin |

### IPv4

#### Get IPv4 class

| Method | URL | Description | Need token | Roles |
| ------ | ---------------- | -------------- | ---------- | ----- |
| GET | /ipv4/class/{ip} | Get IPv4 class | True | User |

#### Convert dec to bin

| Method | URL | Description | Need token | Roles |
| ------ | ---------------------- | ------------------ | ---------- | ----- |
| GET | /ipv4/dec-to-bin/{dec} | Convert dec to bin | True | User |

#### Convert dec to hex

| Method | URL | Description | Need token | Roles |
| ------ | ---------------------- | ------------------ | ---------- | ----- |
| GET | /ipv4/dec-to-hex/{dec} | Convert dec to hex | True | User |

#### Convert hex to dec

| Method | URL | Description | Need token | Roles |
| ------ | ---------------------- | ------------------ | ---------- | ----- |
| GET | /ipv4/hex-to-dec/{hex} | Convert hex to dec | True | User |

#### Convert bin to dec

| Method | URL | Description | Need token | Roles |
| ------ | ---------------------- | ------------------ | ---------- | ----- |
| GET | /ipv4/bin-to-dec/{bin} | Convert bin to dec | True | User |

#### Get CIDR notation

| Method | URL | Description | Need token | Roles |
| ------ | --------------- | ----------------- | ---------- | ----- |
| GET | /ipv4/cidr/{ip} | Get CIDR notation | True | User |

#### Get mask

| Method | URL | Description | Need token | Roles |
| ------ | --------------- | ----------- | ---------- | ----- |
| GET | /ipv4/mask/{ip} | Get mask | True | User |

#### Get VLSM

| Method | URL | Description | Need token | Roles |
| ------ | --------------- | ----------- | ---------- | ----- |
| GET | /ipv4/vlsm/{ip} | Get VLSM | True | User |

### IPv6

#### Simplify IPv6
Expand Down
79 changes: 44 additions & 35 deletions api/src/routes/ipv4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,79 @@

from fastapi import APIRouter, Depends

import utils.IPV4 as ipv4_utils
from dependencies.jwt import jwt_bearer
from utils.IPV4 import (
bin_to_dec,
dec_to_bin,
dec_to_hex,
get_ipv4_mask,
hex_to_dec,
ipv4_class,
ipv4_to_cidr,
vlsm,
)

router = APIRouter()

@router.get("/ipv4_class/{ipv4}", summary="Determines the class of an IPv4 address.",\
@router.get("/class/{ipv4}", summary="Determine the class of an IPv4 address.",\
dependencies=[Depends(jwt_bearer)])
async def get_ipv4_class(ipv4: str) -> dict:
"""Determines the class of an IPv4 address."""
res = ipv4_utils.ipv4_class(ipv4)
"""Determine the class of an IPv4 address."""
res = ipv4_class(ipv4)
return {"ipv4": res}

@router.get("/dec_to_bin/{ipv4}", summary="Converts an IPv4 address from decimal notation to binary notation",\
@router.get("/dec_to_bin/{ipv4}",\
summary="Convert an IPv4 address from decimal notation to binary notation",\
dependencies=[Depends(jwt_bearer)])
async def get_dec_to_bin(ipv4: str) -> dict:
"""Converts an IPv4 address from decimal notation to binary notation"""
res = ipv4_utils.dec_to_bin(ipv4)
"""Convert an IPv4 address from decimal notation to binary notation."""
res = dec_to_bin(ipv4)
return {"ipv4": res}

@router.get("/dec_to_hex/{ipv4}", summary="Converts an IPv4 address from decimal notation to hexadecimal notation",\
@router.get("/dec_to_hex/{ipv4}",\
summary="Convert an IPv4 address from decimal notation to hexadecimal notation",\
dependencies=[Depends(jwt_bearer)])
async def get_dec_to_hex(ipv4: str) -> dict:
"""Converts an IPv4 address from decimal notation to hexadecimal notation"""
res = ipv4_utils.dec_to_hex(ipv4)
"""Convert an IPv4 address from decimal notation to hexadecimal notation."""
res = dec_to_hex(ipv4)
return {"ipv4": res}

@router.get("/hex_to_dec/{ipv4}", summary="Converts an IPv4 address from hexadecimal notation to decimal notation.",\
@router.get("/hex_to_dec/{ipv4}",\
summary="Convert an IPv4 address from hexadecimal notation to decimal notation.",\
dependencies=[Depends(jwt_bearer)])
async def get_hex_to_dec(ipv4: str) -> dict:
"""Converts an IPv4 address from hexadecimal notation to decimal notation."""
res = ipv4_utils.hex_to_dec(ipv4)
"""Convert an IPv4 address from hexadecimal notation to decimal notation."""
res = hex_to_dec(ipv4)
return {"ipv4": res}

@router.get("/bin_to_dec/{ipv4}", summary="Converts an IPv4 address from binary notation to decimal notation.",\
@router.get("/bin_to_dec/{ipv4}",\
summary="Convert an IPv4 address from binary notation to decimal notation.",\
dependencies=[Depends(jwt_bearer)])
async def get_bin_to_dec(ipv4: str) -> dict:
"""Converts an IPv4 address from binary notation to decimal notation."""
res = ipv4_utils.bin_to_dec(ipv4)
"""Convert an IPv4 address from binary notation to decimal notation."""
res = bin_to_dec(ipv4)
return {"ipv4": res}

@router.get("/bin_to_dec/{ipv4}", summary="Converts an IPv4 address from binary notation to decimal notation.",\
@router.get("/cidr/{ipv4}",\
summary="Convert an IPv4 address to CIDR notation.",\
dependencies=[Depends(jwt_bearer)])
async def get_bin_to_dec(ipv4: str) -> dict:
"""Converts an IPv4 address from binary notation to decimal notation."""
res = ipv4_utils.bin_to_dec(ipv4)
async def get_cidr(ipv4: str, mask: str) -> dict:
"""Convert an IPv4 address to CIDR notation."""
res = ipv4_to_cidr(ipv4,mask)
return {"ipv4": res}

@router.get("/ipv4_to_cidr/{ipv4}", summary="Converts an IPv4 address to CIDR notation.",\
@router.get("/mask/{ipv4}",\
summary="Calculate the subnet mask from an IPv4 address in CIDR notation.",\
dependencies=[Depends(jwt_bearer)])
async def get_ipv4_to_cidr(ipv4: str, mask: str) -> dict:
"""Converts an IPv4 address to CIDR notation."""
res = ipv4_utils.ipv4_to_cidr(ipv4,mask)
async def get_mask(ipv4: str) -> dict:
"""Calculate the subnet mask from an IPv4 address in CIDR notation."""
res = get_ipv4_mask(ipv4)
return {"ipv4": res}

@router.get("/get_ivp4_mask/{ipv4}", summary="Calculates the subnet mask from an IPv4 address in CIDR notation.",\
dependencies=[Depends(jwt_bearer)])
async def get_ipv4_mask(ipv4: str) -> dict:
"""Calculates the subnet mask from an IPv4 address in CIDR notation."""
res = ipv4_utils.get_ipv4_mask(ipv4)
return {"ipv4": res}

@router.get("/vlsm/{ipv4}", summary="Implements the VLSM (Variable Length Subnet Mask) technique.",\
@router.get("/vlsm/{ipv4}",\
summary="Implement the VLSM (Variable Length Subnet Mask) technique.",\
dependencies=[Depends(jwt_bearer)])
async def get_vlsm(baseip: str, subnet: str) -> dict:
"""Implements the VLSM (Variable Length Subnet Mask) technique."""
res = ipv4_utils.vlsm(baseip,subnet)
return {"ipv4": res}
"""Implement the VLSM (Variable Length Subnet Mask) technique."""
res = vlsm(baseip,subnet)
return {"ipv4": res}
Loading