this post was submitted on 29 Sep 2021
4 points (100.0% liked)

Asklemmy

43394 readers
1900 users here now

A loosely moderated place to ask open-ended questions

Search asklemmy ๐Ÿ”

If your post meets the following criteria, it's welcome here!

  1. Open-ended question
  2. Not offensive: at this point, we do not have the bandwidth to moderate overtly political discussions. Assume best intent and be excellent to each other.
  3. Not regarding using or support for Lemmy: context, see the list of support communities and tools for finding communities below
  4. Not ad nauseam inducing: please make sure it is a question that would be new to most members
  5. An actual topic of discussion

Looking for support?

Looking for a community?

~Icon~ ~by~ ~@Double_A@discuss.tchncs.de~

founded 5 years ago
MODERATORS
 

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.
you are viewing a single comment's thread
view the rest of the comments
[โ€“] erioque@lemmy.ml 2 points 3 years ago* (last edited 3 years ago)

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