Exists a quicker way to retrieve those IP addresses avoiding to wait some seconds from the GetP2PSessionState API and moreover limiting the risk of having some IP addresses missing from the list.
When the other user accepts the connection, Steam sends a
k_EMsgClientP2PConnectionInfo message to both the users in which are contained the IP addresses of each other.
The content is something like the following:
Code:
valvep2p
udp
IP address
NAT traversal token 1
NAT traversal token 2
stun
and this is the same for all the interfaces of the other user.
The problem is that I have not seen an API or another way that allows to read this information easily, so the only solution at the moment is using
NetHook2.
That project aims to decrypt all the Steam packets and dumping all the low level data sent and received from the Steam server.
It's incredibly useful for debugging purpose but also to verify if everything is working as expected (for example that the IP addresses are shared after having accepted the connection and not before, design issues are ever possible).
So it's enough to go in the folder of its dumps and using the
*in*clientp2pconnectioninfo* filter to get all the packets containing the users IP addresses.
The structure is very simple, the SteamID64 of the target at offset 0x23 and the IP address usually at offset 0x3d:
Code:
3a 15 00 80 11 00 00 00 2a 2a 2a 2a 2a 2a 2a 2a :.......********
2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2a 2a 2a 53 54 45 41 4d 5f 49 44 2a 2a 2a 2a 2a ***STEAM_ID*****
76 61 6c 76 65 70 32 70 00 75 64 70 00 31 31 31 valvep2p.udp.111
2e 32 32 32 2e 33 33 33 2e 34 34 34 00 2a 2a 2a .222.333.444.***
2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
2a 2a 00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a **.*************
2a 2a 2a 00 73 74 75 6e 00 30 00 00 00 00 00 00 ***.stun.0......
Testing NetHook2 is quite simple, you need to have Visual Studio installed, then you must get the headers of zlib and Google protobuf and putting them inside the folder before building the project.
Basically in NetHook2\NetHook2 you must have the folders "Debug", "steam", "google" (containing all the protobuf folder with sourcecode) and "zlib" (containing only zconf.h and zlib.h).
When Steam is running inject the NetHook2.dll library in the Steam.exe process (
RemoteDll is a simple injector).
A console window will popup showing some debug information and the name of the files while they are dumped.
Go in the Steam folder (c:\Program Files (x86)\Steam) and you should see a new folder called
nethook containing another folder composed just by numbers.
That's where are located all the dumped packets.