I am curious to know how you can return ONLY the IP address of the connected user using
ip = socket.getpeername()
Because whenever I use that in my server it returns the IP and socket port, I only want the IP, or at least a way to replace the port with Null... I tried using the replace function but that just gives me an error
attributeError: 'tuple' object has no attribute 'replace
As the error suggests, getpeername returns a tuple. To get the IP you should simply take the first element:
ip = socket.getpeername()[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With