Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hesam-zahiri/p2p_vpn
https://github.com/hesam-zahiri/p2p_vpn
p2p p2p-vpn vpn
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/hesam-zahiri/p2p_vpn
- Owner: hesam-zahiri
- Created: 2023-09-20T10:11:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-20T10:49:32.000Z (over 1 year ago)
- Last Synced: 2024-11-11T05:12:57.250Z (2 months ago)
- Topics: p2p, p2p-vpn, vpn
- Language: Python
- Homepage: https://github.com/hesam-zahiri
- Size: 19.5 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Installation:
```
git clone https://github.com/hesam-zahiri/p2p_vpn.git
```
```
pip install torch
````
# How to use:1- Create a VPN server:
To create a VPN server, use the PyTorch library and the UDP protocol. To do this, open a UDP server and create a UDP channel for each user. Then, for each user, generate a public key and a private key and send the public key to the user.
```
cd p2p_vpn
```
```
python key.py
``````python
import torch
import socket# Create a UDP server socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('0.0.0.0', 12345))# Generate a public-private key pair for each user
users = {}
for i in range(10):
private_key = torch.rand(128)
public_key = private_key * torch.rand(128)
users[i] = {'private_key': private_key, 'public_key': public_key}# Wait for incoming connections
while True:
data, address = server_socket.recvfrom(1024)
user_id, public_key = data.split(':')
user_id = int(user_id)
public_key = torch.tensor(list(map(float, public_key.split(','))))
users[user_id]['peer_address'] = address
users[user_id]['peer_public_key'] = public_key
```
2- Create a VPN client:To create a VPN client, use the PyTorch library and the UDP protocol. To do this, establish a UDP channel with the VPN server and send your public key to the server. Then, use the server's public key to encrypt your data.
```
python p2p_vpn.py
``````python
import torch
import socket# Create a UDP server socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(('0.0.0.0', 12345))# Generate a public-private key pair for each user
users = {}
for i in range(10):
private_key = torch.rand(128)
public_key = private_key * torch.rand(128)
users[i] = {'private_key': private_key, 'public_key': public_key}# Wait for incoming connections
while True:
data, address = server_socket.recvfrom(1024)
user_id, public_key = data.split(':')
user_id = int(user_id)
public_key = torch.tensor(list(map(float, public_key.split(','))))
users[user_id]['peer_address'] = address
users[user_id]['peer_public_key'] = public_key
```
```
python p2p_vpn.py
```
- This is a simple example of a VPN with P2P capability. However, to use this app for P2P, you need to invite other users to join your network and share their public key with you.