Python Forum
my next little project - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Forum & Off Topic (https://python-forum.io/forum-23.html)
+--- Forum: Bar (https://python-forum.io/forum-27.html)
+--- Thread: my next little project (/thread-1276.html)



my next little project - Skaperen - Dec-20-2016

my next little project is to make a "what is my IP address" server, but with UDP and my code (a server and a client) on each end.  so i need to set up a little server that can get the source IP from the UDP datagram it receives and send a UDP response back with the IP address in the data payload as well as the destination address.  i do not need to do IPv6 for this, though i may need to do so some day in the future.


RE: my next little project - wavic - Dec-20-2016

As I know, the UDP doesn't holds into its 'tags' the sender's IP. You just send the packed and that is. No handshake with the server. There is no connection between the client and the server side.


RE: my next little project - Skaperen - Dec-22-2016

when a process receives a UDP datagram, it needs to knew the address it came from, as translated, so it can send a response UDP datagram back to the sender.  if that address is also included in the data payload of the response then the sender can learn its public-visible address.

the API for receiving and sending UDP datagrams needs to enable this.  that's why socket.sendto( string, flags, address ) has that address argument, for example.


RE: my next little project - wavic - Dec-22-2016

When I wrote it I checked if I am not wrong. In all pages I've saw there is nothing more than in and out ports, a check sum, length and the payload.
But there is something called Pseudo Header used for computation of the check sum. And it has the source IP. I did't see this before.

It's better if I try to create such a service and see what'd happen by myself. I am not a network guy.

The address part from the arguments should be for the destination...


RE: my next little project - Skaperen - Dec-24-2016

the code i wrote:
import socket
def main(args):
    p=int(args[1])
    s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.bind(('0.0.0.0',p))
    while True:
        d,ap=s.recvfrom(65536)
        s.sendto(ap[0],ap)