mirror of
https://github.com/hatamiarash7/WireGuard-Config-Generator.git
synced 2025-06-19 08:07:12 +02:00
Create main.py
This commit is contained in:
parent
fd6127269f
commit
8301538a9a
41
main.py
Normal file
41
main.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import environ
|
||||||
|
import json
|
||||||
|
|
||||||
|
env = environ.Env()
|
||||||
|
environ.Env.read_env()
|
||||||
|
|
||||||
|
# Load all IP addresses from the given file
|
||||||
|
|
||||||
|
finalIps = []
|
||||||
|
|
||||||
|
with open('ip-list.json', 'r') as file:
|
||||||
|
lists = json.load(file)
|
||||||
|
for list in lists:
|
||||||
|
for ip in lists[list]:
|
||||||
|
finalIps.append(ip)
|
||||||
|
|
||||||
|
finalIps = ", ".join(map(str, finalIps))
|
||||||
|
|
||||||
|
# Load other config options from .env file
|
||||||
|
|
||||||
|
PrivateKey = env('PRIVATE_KEY')
|
||||||
|
PublicKey = env('PUBLIC_KEY')
|
||||||
|
Address = env('ADDRESS')
|
||||||
|
MTU = env('MTU')
|
||||||
|
PersistentKeepalive = env('PERSISTENT_KEEPALIVE')
|
||||||
|
|
||||||
|
# Generate the config file for each endpoint
|
||||||
|
|
||||||
|
with open('endpoints.json', 'r') as file:
|
||||||
|
endpoints = json.load(file)
|
||||||
|
for endpoint in endpoints:
|
||||||
|
with open(endpoint['name']+'.conf', 'w') as file:
|
||||||
|
file.write('[Interface]\n')
|
||||||
|
file.write('PrivateKey = ' + PrivateKey + '\n')
|
||||||
|
file.write('Address = ' + Address + '\n')
|
||||||
|
file.write('MTU = ' + MTU + '\n\n')
|
||||||
|
file.write('[Peer]\n')
|
||||||
|
file.write('PublicKey = ' + PublicKey + '\n')
|
||||||
|
file.write('AllowedIPs = ' + finalIps + '\n')
|
||||||
|
file.write('Endpoint = ' + endpoint['address'] + '\n')
|
||||||
|
file.write('PersistentKeepalive = ' + PersistentKeepalive + '\n')
|
Loading…
x
Reference in New Issue
Block a user