mirror of
https://github.com/jakobkordez/flex-discovery-proxy.git
synced 2025-05-15 16:20:28 +00:00
Add readme, add arg parse, fix proxy
This commit is contained in:
parent
544d5dd265
commit
fcc4398393
48
README.md
Normal file
48
README.md
Normal file
@ -0,0 +1,48 @@
|
||||
# FlexRadio Discovery Pakcet Proxy
|
||||
|
||||
This project was created to allow connecting to a FlexRadio over a VPN as an
|
||||
alternative to using SmartLink.
|
||||
|
||||
## Why?
|
||||
|
||||
FlexRadio does not want to provide a way to connect to the radio by IP address.
|
||||
The only way to connect to the radio is by recieving a discovery packet from the radio.
|
||||
This is a problem if you want to connect to the radio from a different network when broadcast packets are not forwarded.
|
||||
|
||||
## How?
|
||||
|
||||
The proxy consists of two Python 3 scripts.
|
||||
|
||||
`flex_proxy.py` is the main script that listens for discovery packets and forwards them to the client.
|
||||
It listens for UDP discovery packets on port 4992 and forwards the payload to all clients connected to the TCP socket on port 4996.
|
||||
|
||||
`client.py` connects to the proxy via the TCP socket on port 4996. When a message is recieved, it re-broadcasts it as a UDP packet on port 4992.
|
||||
|
||||
## Usage
|
||||
|
||||
None of the two scripts require any external libraries.
|
||||
All libraries used are part of the Python 3 standard library:
|
||||
|
||||
- `argparse`
|
||||
- `re`
|
||||
- `select`
|
||||
- `socket`
|
||||
- `sys`
|
||||
- `time`
|
||||
|
||||
### Server
|
||||
|
||||
```
|
||||
python3 flex_proxy.py
|
||||
```
|
||||
|
||||
The TCP socket port can be changed by changing the `PORT` variable in `flex_proxy.py`.
|
||||
|
||||
### Client
|
||||
|
||||
```
|
||||
python3 client.py [ip address]
|
||||
```
|
||||
|
||||
The default IP address is `localhost`.
|
||||
It can be changed by changing the `HOST` variable in `client.py` or by passing the IP address as an argument.
|
36
client.py
36
client.py
@ -22,16 +22,50 @@ from socket import (
|
||||
)
|
||||
from select import select
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
import re
|
||||
|
||||
SERVER = "localhost"
|
||||
PORT = 4996
|
||||
|
||||
|
||||
# Argument parsing
|
||||
serverRegex = r"^(?P<host>[^:]+)(:(?P<port>\d+))?$"
|
||||
|
||||
parser = ArgumentParser(
|
||||
prog="FlexRadio discovery proxy client",
|
||||
description="Connect to a FlexRadio discovery proxy and re-broadcast all received packets",
|
||||
epilog="Author: Jakob Kordež, S52KJ",
|
||||
)
|
||||
parser.add_argument(
|
||||
"server",
|
||||
metavar="SERVER",
|
||||
type=str,
|
||||
nargs="?",
|
||||
default=SERVER,
|
||||
help="Server address (default: %(default)s)",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
sp = re.fullmatch(serverRegex, args.server)
|
||||
if not sp:
|
||||
print("Invalid server address")
|
||||
sys.exit(1)
|
||||
|
||||
SERVER = sp.group("host")
|
||||
if sp.group("port"):
|
||||
PORT = int(sp.group("port"))
|
||||
|
||||
|
||||
# Create broadcast socket
|
||||
broadcastSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
|
||||
broadcastSocket.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
|
||||
|
||||
|
||||
# Connect to TCP server
|
||||
with socket(AF_INET, SOCK_STREAM) as s:
|
||||
s.settimeout(5)
|
||||
print("Connecting to server...")
|
||||
print("Connecting to server...", (SERVER, PORT))
|
||||
|
||||
# Try to connect to the server for 5 seconds
|
||||
try:
|
||||
|
@ -67,7 +67,7 @@ try:
|
||||
except:
|
||||
print("Client disconnected")
|
||||
clients.remove(s)
|
||||
except KeyboardInterrupt:
|
||||
except:
|
||||
print("\nExiting...")
|
||||
for s in clients:
|
||||
s.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user