Python Forum
get sender IP on UDP server?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get sender IP on UDP server?
#1
Hello ,
I want to build my own syslog server
I have created a simple Udp server :
import logging
import socket

if __name__ == '__main__':
    UDP_IP = "10.0.0.111"
    UDP_PORT = 5005
    sock = socket.socket(socket.AF_INET,  socket.SOCK_DGRAM)
    sock.bind((UDP_IP, UDP_PORT))
    while True:
        data, addr = sock.recvfrom(1024)  # buffer size is 1024 bytes
        print("From: %s received message: %s" % (addr, data))
when the message is comming I can see this :
From: ('10.0.0.1', 42060) received message: b'script,error this is error test message'
now the '10.0.0.1' IP is the IP of my router and not from the computer how is sending this message
how can I get the IP

*** up until now I have used Splunk(I don't need ot because it have to much on it - and i just need simple things ) , and with the same error message it does show my the remote\client\sender IP
so I guss it is posiable to get

Thanks ,
Reply
#2
Looks okay to me. I wonder if you have some strange networking going on. Unprompted UDP like this shouldn't be subject to NAT, but I have no other explanation. It works fine on my machine. The only change I made was to bind to all addresses so I didn't have to hardcode my IP.

...
if __name__ == '__main__':
    UDP_IP = "0.0.0.0"
    UDP_PORT = 5005
...
Client:
Output:
$ ip -br addr show dev eth0 scope global eth0 UP 10.0.0.10/24 $ echo -n "Test UDP message" > /dev/udp/10.0.0.209/5005 $
Server:
Output:
From: ('10.0.0.10', 58743) received message: b'Test UDP message'
Reply
#3
did you try to send this from outside your netwrok ?
let's say from the internet to the server behind the router?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get sender of email Pedroski55 0 1,582 Dec-03-2022, 09:23 AM
Last Post: Pedroski55
  How to take the tar backup files form remote server to local server sivareddy 0 1,917 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Simple e-mail sender, that automatically changes subject for every e-mail joker 2 3,174 Aug-24-2017, 09:45 AM
Last Post: joker

Forum Jump:

User Panel Messages

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