-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(proxy): Fix whitelist default policy denial (#42)
* fix(proxy): Fix whitelist default policy denial * fix(proxy): Fix whitelist default policy denial * fix(proxy): Fix whitelist default policy denial
- Loading branch information
Showing
4 changed files
with
83 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import ipaddress | ||
import random | ||
import hashlib | ||
import string | ||
|
||
def generate_ip_from_cidr(cidr, session_str): | ||
# Parse the CIDR notation | ||
network = ipaddress.IPv6Network(cidr) | ||
network_address = int(network.network_address) | ||
netmask = int(network.netmask) | ||
|
||
# Combine the CIDR range string and session string | ||
combined_str = f"{cidr}-{session_str}" | ||
|
||
# Generate a hash value from the combined string to use as a seed | ||
seed = int(hashlib.sha1(combined_str.encode()).hexdigest(), 16) | ||
random.seed(seed) | ||
|
||
# Generate a random offset within the network range | ||
offset = random.randint(0, netmask ^ 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) | ||
|
||
# Calculate the IP address using the network address and offset | ||
ip_address_int = network_address + offset | ||
ip_address = ipaddress.IPv6Address(ip_address_int) | ||
|
||
return ip_address | ||
|
||
def session_generator(size, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase): | ||
random.seed(size) | ||
return ''.join(random.choice(chars) for _ in range(size)) | ||
|
||
# Example usage | ||
cidr = "2001:db8::/48" | ||
session_len = 1000 | ||
sessions = [] | ||
|
||
for x in range(session_len): | ||
sessions.append(session_generator(x)) | ||
|
||
result = [] | ||
for x in sessions: | ||
result.append(generate_ip_from_cidr(cidr, x)) | ||
|
||
check = [] | ||
for x in sessions: | ||
check.append(generate_ip_from_cidr(cidr, x)) | ||
|
||
for x in result: | ||
if x not in check: | ||
print(x) |
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