GetClientIP may return the gateway IP address when the client is on the same local network but not the same machine.
Posted: Sun Apr 20, 2025 3:53 pm
To reproduce:
Run this server on one machine:
And run this client on another:
You'll have to replace the IP of the client to match whatever your router is okay with, I don't think 127.0.0.1 will work because they're on different machines, but the same LAN.
Whenever I run this, it returns the IP address of my gateway, not the actual IP address of the client. Can anyone else confirm?
Note, because I was lazy when I coded the server you'll sometimes see 0.0.0.0, just ignore those
Run this server on one machine:
Code: Select all
EnableExplicit
OpenConsole("Server test")
If CreateNetworkServer(0, 10987)
Repeat
Define Event.i = NetworkServerEvent()
If Event
Define ClientID.i = EventClient()
PrintN(IPString(GetClientIP(ClientID)))
EndIf
ForEver
End
EndIf
Code: Select all
EnableExplicit
Define ConnectionID.i = OpenNetworkConnection("ServerIP", 10987)
If ConnectionID
MessageRequester("Client test", "Client connected to server...")
CloseNetworkConnection(ConnectionID)
EndIf
End
Whenever I run this, it returns the IP address of my gateway, not the actual IP address of the client. Can anyone else confirm?
Note, because I was lazy when I coded the server you'll sometimes see 0.0.0.0, just ignore those
