4

I'd need build up an UDP packet with Python setting a particular value of its TTL. Could anyone show me the minimal-length code to do this?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114

1 Answers1

1

Using PyIP.

Not tested, but shows the idea:

import ip
import udp
import socket

# build UDP 
udp_packet = udp.Packet()
udp_packet.sport = 1024;
udp_packet.dport = 3024;
udp_packet.data = "\xFF\xFF\xFF\xFFrcon \"test\" test\0"

udp_data = udp.assemble(udp_packet, 0)

# build IP packet
ip_packet = ip.Packet()
ip_packet.src = "1.1.1.1"
ip_packet.dst = "2.2.2.2"
ip_packet.ttl = 10
ip_packet.data = udp_data
packet = ip.assemble(ip_packet, 0)

# send the packet here
Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162