1

I have a mobile router that can be configured by using different Python script. What I need to do is read all the packets arriving to the router in a concrete UDP port to copy this information in a .txt file afterwards.

Anyone can give me some tips about how can I do this using Python? How can I detect every time a packet arrives in to the router?

Thank you.

1 Answer 1

2

Here's a quick example of how to bind to a UDP port and do some action whenever a datagram is received:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('', 9800))
try:
    while True:
        result, who = s.recvfrom(256)
        print result, who
finally:
    s.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.