I am prototyping a socks5 proxy in Python, I want to get the port number from the connection. I can do it like this with struct.unpack
port = struct.unpack('!H', b'x00P')[0]
print(port) # 80
according to the documentation H
format is for unsigned short
. I wonder is there any way I could convert that byte to unsigned short without using the struct.unpack
. Because I am just prototyping in python but I have to use some other language to build it, I don’t know if the struct.unpack
will exist in other languages.
Is there any way I could destructure that byte without using any python only modules?
Source: Python Questions