I want to check my network client's IP address. If the client uses HTTP, I can get its IP address by letting it connect http://ipinfo.io/ip or the like. But I want to prevent it from using HTTP. Is there any TCP service (server) that acts like http://ipinfo.io/ip but doesn't require HTTP?
For example, I want a server running this python script forever:
import socket
EXAMPLE_PORT = 50007
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', EXAMPLE_PORT))
s.listen(1)
while True:
conn, addr = s.accept()
with conn:
conn.sendall(addr[0].encode())
And I want to run the next python script as my client to get its IP address:
import socket
EXAMPLE_SERVER = 'theserver.xyz'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((EXAMPLE_SERVER, 50007))
data = s.recv(1024)
print("my client's IP address:", repr(data))
Notes:
- I can make the server myself. But I want to know public service if it already exists.
- My client runs on hosts that I don't know their IP addresses.
I use linux btw.