mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 17:20:30 +08:00
ipv6 stun
This commit is contained in:
parent
6ce07208a1
commit
9b4cbfab7f
@ -1,5 +1,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
import socket
|
||||||
|
import ipaddress
|
||||||
import struct
|
import struct
|
||||||
import secrets
|
import secrets
|
||||||
import dataclasses
|
import dataclasses
|
||||||
@ -168,10 +169,9 @@ class Stun:
|
|||||||
|
|
||||||
def __parse_address(self, data: bytes) -> StunAddress:
|
def __parse_address(self, data: bytes) -> StunAddress:
|
||||||
family = data[1]
|
family = data[1]
|
||||||
if family == 1:
|
port = struct.unpack(">H", data[2:4])[0]
|
||||||
parts = struct.unpack(">HBBBB", data[2:8])
|
if family == 0x01:
|
||||||
return StunAddress(
|
return StunAddress(str(ipaddress.IPv4Address(data[4:8])), port)
|
||||||
ip=".".join(map(str, parts[1:])),
|
elif family == 0x02:
|
||||||
port=parts[0],
|
return StunAddress(str(ipaddress.IPv6Address(data[4:20])), port)
|
||||||
)
|
raise RuntimeError(f"Unknown family; received: {family}")
|
||||||
raise RuntimeError(f"Only IPv4 supported; received: {family}")
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user