Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/usr/bin/python3
  2. # Before you start you need to either enable flow label reflection
  3. # sysctl -w net.ipv6.flowlabel_reflect = 1
  4. # or disable flow label consistency
  5. # sysctl -w net.ipv6.flowlabel_consistency = 0
  6.  
  7. import socket
  8. import struct
  9.  
  10. IPV6_FL_A_GET = 0
  11. IPV6_FL_F_REFLECT = 4
  12. IPV6_FLOWLABEL_MGR = 32
  13.  
  14. def prepare_server(listen_port):
  15. sd = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  16. sd.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  17.  
  18. # enable flow reflection if flowlabel_reflect=1
  19. flr_action = IPV6_FL_A_GET
  20. flr_flags = IPV6_FL_F_REFLECT
  21. in6_flowlabel_req = struct.pack("@16sIBBHHHI",
  22. b'\x00'*16, 0, flr_action, 0, flr_flags, 0, 0, 0)
  23.  
  24. try:
  25. sd.setsockopt(socket.IPPROTO_IPV6, IPV6_FLOWLABEL_MGR, in6_flowlabel_req)
  26. except PermissionError:
  27. print("flowlabel_consistency is enabled, I hope you enabled flowlabel_reflect!")
  28.  
  29. sd.bind(('::1', listen_port))
  30. sd.listen(10)
  31. return sd
  32.  
  33. def prepare_client(port):
  34. cd = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  35. cd.connect(('::1', port))
  36. return cd
  37.  
  38. sd = prepare_server(1235)
  39. cd = prepare_client(1235)
  40.  
  41. cd2, cd2_addr = sd.accept()
  42. cd2.close()
  43.  
  44. cd.send(b"a")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement