Python Forum
my next little project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my next little project
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
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...
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
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)
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020