-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
from time import time | ||
from ipaddress import IPv4Address, AddressValueError, IPv4Interface, IPv6Interface | ||
|
||
from config import BGP_NET_SIZE | ||
|
||
start_time = time() | ||
|
||
|
||
def log(msg: str): | ||
print(f'{msg} ({int(time() - start_time)}s)') | ||
|
||
|
||
def get_ip_version(ip: str) -> str: | ||
try: | ||
IPv4Address(ip) | ||
return '4' | ||
|
||
except AddressValueError: | ||
return '6' | ||
|
||
|
||
def get_network_address(ip: str) -> str: | ||
try: | ||
IPv4Address(ip) | ||
return IPv4Interface(f"{ip}/{BGP_NET_SIZE['4']}").network.network_address.compressed | ||
|
||
except AddressValueError: | ||
return IPv6Interface(f"{ip}/{BGP_NET_SIZE['6']}").network.network_address.compressed | ||
|
||
|
||
# def get_network_cidr(ip: str) -> str: | ||
# return f"{get_network_address(ip)}/{BGP_NET_SIZE[get_ip_version(ip)]}" |