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.
@iririr
link
fedilink
48 mois

dig +short myip.opendns.com @resolver.opendns.com

@erioque
creator
link
fedilink
2
edit-2
8 mois

I could get my client’s IP address by your method. I didn’t know such a dns server echoing IP addresses. Thanks, info! Btw, I couldn’t reach resolver.opendns.com. So I used this:

dig +short myip.opendns.com @resolver1.opendns.com
dig +short myip.opendns.com @resolver2.opendns.com

@pinknoise
cake
link
fedilink
4
edit-2
8 mois

Not that I know of. HTTP uses TCP connections, so why don’t you want to use it? Sounds like you are trying to solve the wrong problem.

@erioque
creator
link
fedilink
38 mois

My client must send data like ‘GET /ip HTTP/1.1\r\n…’ after connecting for HTTP servers to get wanted responses. I want to use TCP without HTTP because I want to reduce the data.

A loosely moderated place to ask open ended questions

If your post is

  1. Open ended
  2. Not offensive
  3. Not regarding lemmy support (c/lemmy_support)
  4. not ad nauseam inducing (please make sure its a question that would be new to most members)

it’s welcome here!

  • 0 users online
  • 8 users / day
  • 44 users / week
  • 184 users / month
  • 767 users / 6 months
  • 2.88K subscribers
  • 1.09K Posts
  • 13.7K Comments
  • Modlog