Python Forum
Send UDP packet after bind
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send UDP packet after bind
#1
I want to send a UDP packet to 192.168.0.155 and then listen for replies on the same port as I sent the packet from.
The below code doesn't work. I can't invoke s.sendto after I have binded the socket.
Any suggestions?


import socket
import sys
ip = "127.0.0.1"
port = 42134
# Create a UDP socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = (ip, port)
s.bind(server_address)
print("Do Ctrl+c to exit the program !!")

send_data = 'B:reglistener'
s.sendto(send_data.encode('utf-8'), ("192.168.0.155", 42314))

while True:
    print("####### Server is listening #######")
    data, address = s.recvfrom(4096)
    print("\n\n 2. Server received: ", data.decode('utf-8'), "\n\n")
    send_data = input("Type some text to send => ")
    s.sendto(send_data.encode('utf-8'), address)
    print("\n\n 1. Server sent : ", send_data,"\n\n")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sending packet onto dummy network device but receiving echo sabuzaki 2 1,412 Feb-12-2023, 10:31 AM
Last Post: Vadanane
  How to send a HTTP response packet using scapy JeffreyStoner 0 2,628 Apr-18-2022, 05:23 AM
Last Post: JeffreyStoner
  Need Help with creating an IP packet with timestamp field using Scapy RTD 0 3,430 Jun-15-2019, 08:21 PM
Last Post: RTD
  Need Help W/ Simple Packet Capture Code Caesars_10th 3 3,308 Mar-11-2019, 08:28 PM
Last Post: Larz60+
  UDP Listen without Bind() GaryFunk 3 8,405 Mar-29-2018, 02:28 AM
Last Post: DeaD_EyE
  Failed to recieve scapy udp packet SkyAmryBoi 1 3,781 Sep-29-2017, 01:26 PM
Last Post: camp0

Forum Jump:

User Panel Messages

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