Read the Packet header Information

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjayrjain
    New Member
    • Feb 2010
    • 3

    Read the Packet header Information

    Hi,

    How can i read the packet header information like Source address , destination address, TTL value from a UDP Packet in python.
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    It depends. How did you get said UDP packet?
    Are you using the socket library or another library like scappy or pycap?

    Comment

    • sanjayrjain
      New Member
      • Feb 2010
      • 3

      #3
      I'm getting using socket library.

      Something like this:

      [code=python]
      sock = socket.socket(s ocket.AF_INET, socket.SOCK_DGR AM, socket.IPPROTO_ UDP)
      sock.setsockopt (socket.SOL_SOC KET, socket.SO_REUSE ADDR, 1)
      sock.bind(('', rec_port))
      print "Connected to Destination Host named:", rec_hostname

      # Set some more multicast options
      mreq = struct.pack('4s l', socket.inet_ato n(rec_hostname) , socket.INADDR_A NY, socket.IP_MULTI CAST_TTL)
      sock.setsockopt (socket.IPPROTO _IP, socket.IP_ADD_M EMBERSHIP, mreq)
      while True:
      data = sock.recv(1024)
      print "Message Received:" , data
      sock.close()[/code]
      Last edited by bvdet; Feb 25 '10, 02:12 PM. Reason: Add code tags

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Please use code tags when posting code. See posting guidelines here.

        BV - Moderator

        Comment

        Working...