Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. def create_DNS_query(hostname):
  2. packet = struct.pack("!H", 12049) # Query Ids (Just 12049, Can randomize if you want)
  3. packet += struct.pack("!H", 256) # Flags (0x0100, Recursive Query)
  4. packet += struct.pack("!H", 1) # Questions
  5. packet += struct.pack("!H", 0) # Answers RRs
  6. packet += struct.pack("!H", 0) # Authorities RRs
  7. packet += struct.pack("!H", 0) # Additional RRs
  8. split_url = hostname.split(".")
  9. for part in split_url:
  10. packet += struct.pack("B", len(part))
  11. for byte in part:
  12. packet += struct.pack("c", byte.encode('ascii'))
  13. packet += struct.pack("B", 0) # End of String (implies that there is no URL information ahead)
  14. packet += struct.pack("!H", 1) # Query Type
  15. packet += struct.pack("!H", 1) # Query Class
  16. return packet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement