Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any alternative to echo daemon to display ip instead of given string?

For ex: my ip = 80.1.2.3

server ip = 1.2.3.4

root@my-machine bash$ telnet 1.2.3.4
Trying 1.2.3.4...
Connected to 1.2.3.4.
Escape character is '^]'.
80.1.2.3
share|improve this question
1  
What would you need this for? This sounds like a case of the XY problem. It might be better to ask a question about what you actually want to achieve using this. –  Thomas Nyman Oct 25 '13 at 8:50
    
I got my monitoring server, also i got lots of clients behind the NAT all over the world. Of course there are a lot of different network configurations. So I want to know their external ip. (clients can connect to server) –  Mark van-Hauser Oct 25 '13 at 8:52
    
There are web services, which do this. From a shell you could get the the external IP via for instance wget http://ipecho.net/plain -O - -q ; echo –  Thomas Nyman Oct 25 '13 at 8:58
    
unfortunately there is no access to ipecho.net =( –  Mark van-Hauser Oct 25 '13 at 9:04

3 Answers 3

up vote 3 down vote accepted

Here's a small implementation of what you want in Python (run it as server.py <port>:

#!/usr/bin/env python

import socket
import sys

_, port = sys.argv

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", int(port)))
sock.listen(1)

while True:
    conn, addr = sock.accept()
    ip, port = addr
    conn.send(ip.encode("ascii") + b"\n")
    conn.close()
$ ./server.py 1234 &
[1] 20315
$ nc localhost 1234
127.0.0.1
$
share|improve this answer
    
Thank you! Already did it with ruby =) –  Mark van-Hauser Oct 25 '13 at 10:53

With socat:

socat tcp-listen:12345,reuseaddr,fork system:'echo "$SOCAT_PEERADDR"'
share|improve this answer

In short, no. The Echo Protocol description in RFC 862 is very simple and unambigious:

TCP Based Echo Service

One echo service is defined as a connection based application on TCP. A server listens for TCP connections on TCP port 7. Once a connection is established any data received is sent back. This continues until the calling user terminates the connection.

UDP Based Echo Service

Another echo service is defined as a datagram based application on UDP. A server listens for UDP datagrams on UDP port 7. When a datagram is received, the data from it is sent back in an answering datagram.

share|improve this answer
    
Yeah, I know it. So is there a kind of echo service that will provide me with external ip like ipecho.net/plain, but on tcp layer level. –  Mark van-Hauser Oct 25 '13 at 8:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.